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

Code not working? No error in output yet it still does most but not all.

Here is the code:

local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
	local redgear = game.ReplicatedStorage:WaitForChild("Five-Seven Candy")
	if plr.Backpack:FindFirstChild('KF5') or plr.StarterGear:FindFirstChild('KF5') or game.Workspace[plr.Name]:FindFirstChild('KF5') then
	if 	plr.Backpack:FindFirstChild('KF5') then
		plr.Backpack:FindFirstChild('KF5'):Destroy()
	end
	if 	plr.StarterGear:FindFirstChild('KF5') then
		plr.StarterGear:FindFirstChild('KF5'):Destroy()
	end
	
if 	game.Workspace[plr.Name]:FindFirstChild('KF5') then
	 	game.Workspace[plr.Name]:FindFirstChild('KF5'):Destroy()
end
	end
	redgear:Clone().Parent = plr.Backpack -- FROM HERE ON IS THE RESPAWN AND TEAMCHANGE
	redgear:Clone().Parent = plr.StarterGear
	plr.TeamColor = BrickColor.new('Bright red') -- teamchange	
	plr:LoadCharacter() -- respawn
end)

So, all I know is that the section labeled "teamchange" and "respawn" is NOT working, sadly. I make it so that local plr = game.Players.LocalPlayer which makes it so that plr = localplayer. then when it goes to teamchange, I have the simple stuff done, like the teamcolor. The spawn color matches bright red. I see no issues, and plr:LoadCharacter is a respawn function so you dont have to wait 5 seconds + a death, if anyone can help me out here it would be much apperciated. Thanks, bye.

1 answer

LoadCharacter

A look at the API says that you need to have LoadCharacter in a regular Script and not a LocalScript. If it just so happens that this code is in a regular Script, you seriously need to reconsider how you're getting input; LocalPlayer doesn't exist on the server.

You'll need a RemoteEvent to ask the server to do this. Just connect the mouse to the RemoteEvent instead, and move the code to a RemoteEvent connection. Simples.

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