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 make a skip stage button?

So I'm trying to make have a button that skips a stage and I don't know how to do it. I made the stage names 1 2 3 4. I'm trying to convert them to an int and add one to them and then back to a string.

TextButton.MouseButton1Up:Connect(function()
	local player = game.Players.LocalPlayer
	local teamname = player.Team.Name
	local teamnumber = tonumber(teamname)    
	local newteam = tostring(teamnumber + 1)
	print(newteam)
	print(player.Team.Name)
	player.Team = game.Teams[newteam]
	print(player.Team.Name)
	player.Character.Humanoid.Health = 0
end)

I doesn't update and I always respawn on the stage I was on. But when I look at the player information, it says I am on the next stage when I don't respawn there. Also, how do I respawn the player without killing them?

3 comments

0

Well, if you're going to change the team, don't do it on the client. The server won't read the change.

0

Also, just teleport the player to the spawn location if you don't want to kill them. You can also mess around with their forcefield if you want to keep it or change it.

0

how do I do it on the client side? do I put a script in the player scripts so that when that GUI is clicked, the team changes?

1 answer

Use RemoteEvents. It is a way of communicating between the server and the client. Due to FilteringEnabled (which is made to prevent exploiters from ruining games like they used to), LocalScripts need RemoteEvents and RemoteFunctions to communicate to the server, otherwise everything is only done on the Client side.

You can read more about it here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

Anyway, here is how you would do this:

First, make a RemoteEvent in ReplicatedStorage named “StageSkip”

Change your local script to this:


TextButton.MouseButton1Up:Connect(function()
      local Remote = game:GetService(“ReplicatedStorage”)[“StageSkip”] -- Finds the remote
      Remote:FireServer() -- Fires it
end)

And then make a new script (preferably in ServerScriptService) and put this in the script:

local Remote = game:GetService(“ReplicatedStorage”)[“StageSkip”]

function SkipStage(player)
      local teamname = player.Team.Name
    local teamnumber = tonumber(teamname)    
    local newteam = tostring(teamnumber + 1)
    print(newteam)
    print(player.Team.Name)
    player.Team = game.Teams[newteam]
    print(player.Team.Name)
    player:LoadCharacter() -- Respawns the player without killing them
end

Remote.OnServerEvent:Connect(SkipStage)

What this does is, when the button is clicked, it fires the RemoteEvent, telling the server that someone has skipped a stage. Then, the RemoteEvent connects to that and does the same thing in your LocalScript but now the Server actually registers everything.

4 comments

0

Also change the quotation marks because my keyboard is weird.

0

I have a question, do I just do localplayer for the player?

0

dude thanks you are epic

0

thanks dude!

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