Reputation: 3
im trying to make a points system that gives 10 points if the player survived the round. how it works: the player touches the part in the begining of the round and the roundvalue becomes true. when the player tps to lobby and touches the part in the lobby the value of the round becones false and he gets 10 point only if he survives. i tried everything and i just don't understand why i got this error. help would be appriciated! thx.
Players = game:GetService("Players")
local part = script.Parent
local lobbypart = workspace.LobbyPart
local inround = false
local SurvivedPoints = 10
local function givepoints(player)
local playerstats = player:WaitForChild("leaderstats") -- problem here
local playerpoints = playerstats:WaitForChild("Points") -- problem here
playerpoints.Value = playerpoints.Value + SurvivedPoints
end
local function ontouched(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
inround = true
print("Round begins")
end
local function inlobby(otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player and inround == true then
inround = false
print("round ended")
givepoints()
end
end
lobbypart.Touched:Connect(inlobby)
end
part.Touched:Connect(ontouched)
Upvotes: 0
Views: 444
Reputation: 7188
Your givePoints(player)
function you created expects you to give it a player. But when you called it, you didn't supply one. Just pass in the player object.
local function inlobby(otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player and inround == true then
inround = false
print("round ended")
givepoints(player)
end
end
Upvotes: 1