Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

GetPlayerFromCharecter

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....

1 comment

0

You use the method GetPlayerFromCharacter on Game.Players, not Workspace.

1 answer

✓ Accepted answer
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)

1 comment

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.