game.Players is a service, not the LocalPlayer.
You're obviously trying to get the leaderstats of the player that Touched the part. In order to do this, I would suggest using the GetPlayerFromCharacter() function from the players service. First, let's get the character. To do this, simply use part.Parent. To know for sure if the part's parent is the character, check if it has a Humanoid, like so,
function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
end
end
script.Parent.Touched:connect(onTouch)
Now we can Define the character,
function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local char = part.Parent
end
end
script.Parent.Touched:connect(onTouch)
Now we get the player by using GetPlayerFromCharacter. Like so,
function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local char = part.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
end
end
script.Parent.Touched:connect(onTouch)
Now we can throw your code in there!
EDIT, fixed error.
function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local char = part.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local check1 = plr:WaitForChild("leaderstats")
if check1 then
local check2 = plr:WaitForChild("Owner")
if check2 then
local check3 = check2.Value
if check3 then
check3 = true
end
end
end
end
end
script.Parent.Touched:connect(onTouch)
That should work.
However, it seems what you were going for was this,
function onTouch(hit)
local name = hit.Parent.Name
if name then
local check1 = game.Players[name]:WaitForChild("leaderstats")
if check1 then
local check2 = game.Players[name]:WaitForChild("Owner")
if check2 then
local check3 = check2.Value
if check3 then
check3 = true
end
end
end
end
end
script.Parent.Touched:connect(onTouch)
or
function onTouch(hit)
local name = hit.Parent.Name
if name then
local check1 = game.Players:FindFirstChild(name):WaitForChild("leaderstats")
if check1 then
local check2 = game.PlayersFindFirstChild(name):WaitForChild("Owner")
if check2 then
local check3 = check2.Value
if check3 then
check3 = true
end
end
end
end
end
script.Parent.Touched:connect(onTouch)
Which would work, but I just provided a slightly better way.
Good Luck!
1 comment
the script looks confusing, and there is no errors shown unless there is none