Instant respawn after changing team

I have a script where when you select a team it will instantly respawn you the only thing is it doesnt respawn you. Here is what i have so far.

The Local Script

local plyr = game:GetService("Players").LocalPlayer
respawn=game.ReplicatedStorage.RespawnHandler:WaitForChild("Respawn") --finding the remote


script.Parent.MouseButton1Click:Connect(function()
if plyr:GetRankInGroup(6041317) >= 2 then
	plyr.TeamColor = BrickColor.new("Teal")
	respawn:FireServer() --Firing the remote
end
end)

Script in replicated storage

event=Instance.new("RemoteEvent", script)
event.Name="Respawn"
event.OnServerEvent:connect(function(player)player:LoadCharacter() end)

Here is where i have the script and the remote event
dtx2mJw

4 Likes

Do any errors appear in the output?

Here is the error i forgot to put in main thread.

Ah, the problem is that ReplicatedStorage wont run that script. Move it to ServerScriptService and parent the event to ReplicatedStorage rather than to the script.

1 Like

Like This? I put it in server script service and edited my code to match it

1 Like

No, not like that. Keep the parent of the event set to

game.ReplicatedStorage

Instead of to the script.

Only move the script to ServerScriptService.

1 Like

drag the script into serverscriptservice and put the remote to replicatedstorage then fix your code to get the corresponding variables in order for it to function, if it doesnt work (when it should) please elaborate, and ill enunciate the error if i find it

Make sure the Respawn event is in ReplicatedStorage. The script running the respawn should be in ServerScriptService. I also recommend game:GetService(‚ÄúReplicatedStorage‚ÄĚ) over game.ReplicatedStorage as sometimes the name of ReplicatedStorage can get changed (usually by intention)

Ok, your script has alot of problems.
Let me show you a fix:

--// LocalScript In Gui
local ReplicatedService = game:GetService("ReplicatedStorage");
local plyr = game:GetService("Players").LocalPlayer
local respawn = ReplicatedService:WaitForChild("Respawn");


script.Parent.MouseButton1Click:Connect(function()
	respawn:FireServer();
end)
--// Script In ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage");

local Event = Instance.new("RemoteEvent", ReplicatedStorage);
Event.Name = "Respawn";

Event.OnServerEvent:connect(function(player)
    if player:GetRankInGroup(6041317) >= 2 then
       player.TeamColor = BrickColor.new("Teal");
       player:LoadCharacter();
    end
end)
4 Likes

Thanks Alot! Sorry if i caused you any trouble im pretty new at scripting.