I need help wih setting up the player's RespawnLocation. Can yall help me?

So i made two buttons, which will make the player’s RespawnLocation change when ever Clicked. The problem is that I have two kinds of Respawns in my game, My game is a combination with a Tycoon and an Obby, so there’s Respawns for the Obby and Respawns for the Tycoon. And i want to make the player choice where ever he wants to spawn. But for some reason my code doesnt work, i havent ever messed with player RespawnLocation so i’ll need your guys help here to find out what i did wrong, thanks!
I didnt manage to find a similar problem to mine on this forum. maybe im blind idk.
and yea. both of them not work…
Set Tycoon RespawnLocation

local players = game:GetService("Players")
local obbyv =  script.Parent.Parent.ObbyButton.Value
local tycoonv =  script.Parent.Value
local Teams = game:GetService("Teams")`
    script.Parent.MouseButton1Click:Connect(function(plr)
    plr = players.LocalPlayer   
    if plr.Team == Teams.Red then

        obbyv.Value = false
        tycoonv.Value = true    
        if tycoonv.Value == true then
            script.Parent.BackgroundColor3 = Color3.new(0.545098, 0.545098, 0)
            script.Parent.Shadow.BackgroundColor3 = Color3.new(0.282353, 0.282353, 0)

            script.Parent.Parent.ObbyButton.BackgroundColor3 = Color3.new(255, 0, 0)
            script.Parent.Parent.ObbyButton.Shadow.BackgroundColor3 = Color3.new(0.290196, 0, 0)
            plr.RespawnLocation = game.Workspace.Cloud1.SpawnLocation

        end

    end
end)

Set Obby Spawn:

local players = game:GetService("Players")
local Cpoints = game.Workspace.CheckPoints:GetChildren()
local obbyv =  script.Parent.Value
local tycoonv =  script.Parent.Parent.TycoonButton.Value
local Teams = game:GetService("Teams")
    script.Parent.MouseButton1Click:Connect(function(char)

        local player = players.LocalPlayer
        local leaderstats = player:FindFirstChild("leaderstats")
        local Stage = leaderstats:FindFirstChild("Stage")
        if player.Team == Teams.Red then
            obbyv.Value = true
            tycoonv.Value = false
            if obbyv.Value == true then

                player.RespawnLocation = Cpoints[Stage.Value]


                script.Parent.BackgroundColor3 = Color3.new(0.545098, 0.545098, 0)
                script.Parent.Shadow.BackgroundColor3 = Color3.new(0.282353, 0.282353, 0)

                script.Parent.Parent.TycoonButton.BackgroundColor3 = Color3.new(255, 0, 0)
                script.Parent.Parent.TycoonButton.Shadow.BackgroundColor3 = Color3.new(0.290196, 0, 0)

            end
        end


    end)

and also the Stages leaderstats code, maybe the problem is here idk:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"

	local points = Instance.new("IntValue",leaderstats)
	points.Name = "points"
	points.Value = 0

	local Stage = Instance.new("IntValue",leaderstats)
	Stage.Name = "Stage"
	Stage.Value = 0

	local Cpoints = game.Workspace.CheckPoints

	player.CharacterAdded:Connect(function(char)
		local hum = char:FindFirstChild("Humanoid")
		wait()
		char:MoveTo(Cpoints[Stage.Value].Position)
		hum.Touched:Connect(function(hit)
			if hit.Parent == Cpoints then
				if tonumber(hit.Name) == Stage.Value + 1 then
					Stage.Value = Stage.Value + 1
				end
			
			end
		end)
	end)

Thanks!

1 Like

You have to change the player’s respawn location via server.

1 Like

Do you get anything in the output box that is concerning, such as an error or stack message?

no there is no error. but the script is a local script. maybe i need to change that to a regular script. will that make a change?

On your Set Tycoon RespawnLocation, it seems you made a typo: “local Teams = game:GetService(“Teams”)`” Remove the " ’ " if you haven’t already.

As well, on your leaderstats code, there’s an error but it might be a typo. It should be like this:

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”,player)
leaderstats.Name = “leaderstats”

local points = Instance.new("IntValue",leaderstats)
points.Name = "points"
points.Value = 0

local Stage = Instance.new("IntValue",leaderstats)
Stage.Name = "Stage"
Stage.Value = 0

local Cpoints = game.Workspace.CheckPoints

player.CharacterAdded:Connect(function(char)
	local hum = char:FindFirstChild("Humanoid")
	wait()
	char:MoveTo(Cpoints[Stage.Value].Position)
	hum.Touched:Connect(function(hit)
		if hit.Parent == Cpoints then
			if tonumber(hit.Name) == Stage.Value + 1 then
				Stage.Value = Stage.Value + 1
			end
		end
	end)
end)

end)

Add your scripts as scripts from the server and not from the client.

I don’t think so if its detecting if a button is pressed, you could maybe add a clickdetecter than do a regular script, then detect the clickdetecter and change the LocalPlayer spawnpoint (if that is possible, i’m not sure)

1 Like

what do you mean by scripts from the server and not from the client?

I think they mean to change your code to scripts, because scripts run on the server, and LocalScripts run on the client. Also, you may need to setup a RemoteEvent for this.

In the first script, MouseButton1Click is detected on the client, so it can’t change the SpawnLocation, as that runs on the player, I would try to setup a remote event. Apart from the stuff that should be running on the server, your first script looks good!

Hey, sorry for the late reply. But i cant figure out how to use the remote events. i’ve tried what you told me to do, to use RemoteEvents. So i “Converted” both of the scritps to “work” and moved them to the ServerScriptService. And i really dont know how to use them.
here are the scritps:

local ChangeOEvent = script.Parent.Parent.ReplicatedStorage.ChangeSpawn1
local players = game:GetService("Players")
local Cpoints = game.Workspace.CheckPoints:GetChildren()
local obbyv =  game.StarterGui.InsertedObjects.ObbyButton.Value
local tycoonv =  game.StarterGui.InsertedObjects.TycoonButton.Value
local Teams = game:GetService("Teams")
ChangeOEvent.OnServerEvent:Connect(function(Player)
	
	local player = players.LocalPlayer
	local leaderstats = player:FindFirstChild("leaderstats")
	local Stage = leaderstats:FindFirstChild("Stage")
	if player.Team == Teams.Red then
		obbyv.Value = true
		tycoonv.Value = false
		if obbyv.Value == true then

			player.RespawnLocation = Cpoints[Stage.Value]


			script.Parent.BackgroundColor3 = Color3.new(0.545098, 0.545098, 0)
			script.Parent.Shadow.BackgroundColor3 = Color3.new(0.282353, 0.282353, 0)

			script.Parent.Parent.TycoonButton.BackgroundColor3 = Color3.new(255, 0, 0)
			script.Parent.Parent.TycoonButton.Shadow.BackgroundColor3 = Color3.new(0.290196, 0, 0)

		end
	end
end)

2nd one:

local Event = script.Parent.Parent.ReplicatedStorage.ChangeSpawn2
local players = game:GetService("Players")
local obbyv =  game.StarterGui.InsertedObjects.ObbyButton.Value
local tycoonv =  game.StarterGui.InsertedObjects.TycoonButton.Value
local Teams = game:GetService("Teams")
Event.OnServerEvent:Connect(function(Player)
local plr = players.LocalPlayer	
	if plr.Team == Teams.Red then

		obbyv.Value = false
		tycoonv.Value = true	
		if tycoonv.Value == true then
			script.Parent.BackgroundColor3 = Color3.new(0.545098, 0.545098, 0)
			script.Parent.Shadow.BackgroundColor3 = Color3.new(0.282353, 0.282353, 0)

			script.Parent.Parent.ObbyButton.BackgroundColor3 = Color3.new(255, 0, 0)
			script.Parent.Parent.ObbyButton.Shadow.BackgroundColor3 = Color3.new(0.290196, 0, 0)
			plr.RespawnLocation = game.Workspace.Cloud1.SpawnLocation

		end

	end

end)

and then i did this: THIS IS THE IMPORTANT PART:

script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.ChangeSpawn1:FireServer(script.Parent)
end)

it didnt work and i got this error:
FireServer can only be called from the client
and then i tried maybe switching it to FireClient
and i got this error:
FireClient: player argument must be a Player object
i really dont know how this stuff work lol. anyway i can fix this?
and did i “Convert” the codes right?

The first error, I would imagine you are trying to fire something from the server to the server, which doesn’t really make sense. The second error is a little more tricky than that though. Which script gave you the message, if its the last one that you said was super important, try putting in a player parameter and then replace this game.ReplicatedStorage.ChangeSpawn1:FireServer(script.Parent), with this:

script.Parent.MouseButton1Click:Connect(function(player) -- I'm pretty sure this is the player object
game.ReplicatedStorage.ChangeSpawn1:FireServer(player)
end)

I’ve gotten that error before too. Please let me know if this doesn’t help!

As for whether you converted to codes right, I can’t really answer that because its not my code. If it (Assuming that the RemoteEvent works) sets the RespawnLocation to how you want it, then you converted it right. It’s just a matter of whether it works or not.

Doesnt seem to work. im trying to figure out another way to set it up. i’ll update ya if i can do it.

About error with “FireServer can only be called frm the client” are you using local script to fire server?

Yea, it was but i dont want to mess with remote events, its really confusing to me. and i think i’ve found a solution but im facing an error in my leaderstats script. here have a look:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	print(player.Name)
	local Cash = Instance.new("IntValue",leaderstats)
	Cash.Name = "Cash"
	Cash.Value = 0
	local Stage = Instance.new("IntValue",leaderstats)
	Stage.Name = "Stage"
	Stage.Value = 0

	local Cpoints = game.Workspace.CheckPoints
	local Teams = game:GetService("Teams")
	player.CharacterAdded:Connect(function(char)
		local obbyv =  player:WaitForChild("ObbyV")
		local tycoonv = player:WaitForChild("TycoonV")
		
		local hum = char:FindFirstChild("Humanoid")
		wait()
		if obbyv.Value == true then
			char:MoveTo(Cpoints[Stage.Value].Position)
			print("good")
		end
		hum.Touched:Connect(function(hit)
				if hit.Parent == Cpoints then
					if tonumber(hit.Name) == Stage.Value + 1 then
						Stage.Value = Stage.Value + 1
					end

				end
			end)

		--end

	end)
	
end)

for some reason, the stage value doesnt increase by 1 when touched. if i remove the If obbyv.Value == true then
then it works
any help?