Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

GetPlayerFromCharecter

Asked by 10 years ago
function onTouched(part)
    if part.Name == "Left Leg" or part.Name == "Right Leg" then
        local player = game.Workspace:GetPlayerFromCharacter(part.Parent)
        player.leadstats.Money.Value = script.Parent.Money.Value+player.leadstats.Money.Value
        script.Parent.Parent.Main:remove()
    end
end


script.Parent.Touched:connect(onTouched)

it says GetPlayerFromCharecter Is not a vaild member of Workspace....

0
You use the method GetPlayerFromCharacter on Game.Players, not Workspace. Thewsomeguy 448 — 10y

1 answer

Log in to vote
3
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago
Edited 4 years ago
local main = script.Parent.Parent:WaitForChild("Main")
function onTouched(part)
    if part.Name == "Left Leg" or part.Name == "Right Leg" then
        local player = game.Players:GetPlayerFromCharacter(part.Parent)
        local leaderstats = player and player:findFirstChild("leaderstats")
        local money = leaderstats and leaderstats:findFirstChild("Money")
        if money then
            money.Value = money.Value +5
            if main then main:Destroy() end
        end
    end
end


script.Parent.Touched:Connect(onTouched)
0
Thanks DeveloperAtWork 14 — 10y
Ad

Answer this question