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

How do I load character a player that was touched by a part?

--Script inserted in handcuffs handle tm = script.Parent

local RemoteEvent = game.ReplicatedStorage.ChangeTeam1

function onTouched(hit)

local h = hit.Parent:FindFirstChild("Humanoid")

if h ~= nil then

local n = hit.Parent

local player = game.Players:FindFirstChild(""..n.Name.."")

if player.Team ~= game.Teams.Police then

local PrisonersColor = "Deep orange"

RemoteEvent:FireServer(BrickColor.new(PrisonersColor))

else

--does nothing

end

end

end

script.Parent.Touched:connect(onTouched)

--script in serverscriptservice game.ReplicatedStorage.ChangeTeam1.OnServerEvent:Connect(function(player, teamColor)

if player.Team ~= game.Teams.Police then

player.TeamColor = teamColor

player:LoadCharacter()

end

end)

1 answer

Try getting the player like this, the function does exactly what it says, gets the player from the character.

local character = h.Parent
local player = game.Players:GetPlayerFromCharacter(character)

1 comment

0

Nevermind, Fixed this.

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