How do i make this code execute on the serverside?

local teleportService = game:GetService("TeleportService")

game.Players.PlayerAdded:Connect(function(plr)
	if true then
		local guiFrame = plr:WaitForChild("PlayerGui"):WaitForChild("QueueGui").QueueScreenFrame
		guiFrame.QueueButton.MouseButton1Click:Connect(function()
			if true then
				local player = guiFrame.Parent.Parent.Parent
				script.Queue.Value = script.Queue.Value + 10
				guiFrame.QueueLabel.Text = script.Queue.Value.. "/20 in queue"
				guiFrame.TutorialButton.Visible = false
				guiFrame.ShopButton.Visible = false
				guiFrame.QueueButton.Visible = false
				if script.Queue.Value == 20 then
					task.wait(1)
					teleportService:Teleport(14453697332, player)
					script.Queue.Value = 0
					guiFrame.QueueLabel.Text = script.Queue.Value.. "/20 in queue"
					script.CountdownValue.Value = 30
					guiFrame.Countdown.Text = script.CountdownValue.Value
					guiFrame.Countdown.Visible = false
				end
				if script.Queue.Value == 10 then
					guiFrame.Countdown.Visible = true
					guiFrame.Countdown.Text = script.CountdownValue.Value
					for i = 1, 30 do
						script.CountdownValue.Value = script.CountdownValue.Value - 1
						guiFrame.Countdown.Text = script.CountdownValue.Value
						task.wait(1)
					end
					if script.CountdownValue.Value == 0 then
						script.Queue.Value = 0
						guiFrame.QueueLabel.Text = script.Queue.Value.. "/20 in queue"
						script.CountdownValue.Value = 30
						guiFrame.Countdown.Text = script.CountdownValue.Value
						guiFrame.Countdown.Visible = false
						teleportService:Teleport(14453697332, player)
					end
				end
			end
		end)
	end
end)

how do i make this script execute on the serverside? i am making a flicker-inspired game, and this is the script for the queue to enter the game. i put the script in a server script and everything, but for some reason, it acts as if it was in a local script. i tried to change “player.playergui” to “game.startergui” but then the script didnt run at all. please help (the “+10” is just for testing purposes)

6 Likes

also keep in mind that im a beginner scripter, so the code probably sucks

3 Likes

I haven’t read the whole thing as it will take some time to understand it (quite messy) but i can tell one of the issues.
You need to handle button pressing on the client and use RemoteEvents to send it to the server

3 Likes

the way i was testing it was that i would first make player 1 join, then hit the queue button, then make player 2 join, and then hit the queue button again

i did as you suggested, and tested the game in the same way, but now the player2s value upon entering the queue is 20, while player1s value is 10. it was actually like this before but i thought fixing the serverside problem would fix it but apparently not. also, the queue still doesnt show the correct value when player2 joins for some reason, but the script is now serverside for player 1

2 Likes

that’s because the Queue value is generic and will increment by 10 for everytime the button is pressed. if you want it to be specific to 1 player then either have a table with different values for each player.

local Queue = {}
--when player joins
Queue[player]  = 0
-- when using it
Queue[player] += 10 

or have the IntValue Queue inside of each player folder

4 Likes

tried it, player 1 is still the only one on the serverside, but thankfully player 2s queue value isnt 20 anymore, so player 1 gets teleported and player 2 doesnt. still need a fix tho

edit: will try the second suggestion i forgot

3 Likes

What would be a fix i dont quite understand.
can you paste the new code and tell me what exactly do you want to happen now

3 Likes

i want both players to get teleported as long as they press the queue button, so that its a proper queue

3 Likes

tried the second suggestion, same thing happens unfortunately

2 Likes

and player 2 doesn’t teleport right ? can you paste the code using Queue variable

3 Likes

You check if the value equals 0 after you check if the value equals 10. I dont think that its intentional. if it isnt, change the part to:

if script.Queue.Value == 10 then
	guiFrame.Countdown.Visible = true
	guiFrame.Countdown.Text = script.CountdownValue.Value
	for i = 1, 30 do
		script.CountdownValue.Value = script.CountdownValue.Value - 1
		guiFrame.Countdown.Text = script.CountdownValue.Value
		task.wait(1)
	end
end
if script.CountdownValue.Value == 0 then
	script.Queue.Value = 0
	guiFrame.QueueLabel.Text = script.Queue.Value.. "/20 in queue"
	script.CountdownValue.Value = 30
	guiFrame.Countdown.Text = script.CountdownValue.Value
	guiFrame.Countdown.Visible = false
	teleportService:Teleport(14453697332, player)
end
1 Like

that’s CountdownValue not Queue :smile:

2 Likes

haha I misread it sorry
(character limit)

3 Likes

im not too sure what you mean by “queue variable” as i thought both of the scripting suggestions included a “queue” variable, and all of your suggestions were still a step up from the original script, so heres the script from the last suggestion you gave, hope i got it right lol, again, im a beginner scripter so i dont know my stuff

game.Players.PlayerAdded:Connect(function(plr)
	if true then
		local queue = Instance.new("NumberValue")
		queue.Parent = plr
		local guiFrame = plr:WaitForChild("PlayerGui"):WaitForChild("QueueGui").QueueScreenFrame
		queueEvent.OnServerEvent:Connect(function()
			if true then
				local player = guiFrame.Parent.Parent.Parent
				queue.Value = queue.Value + 10
				guiFrame.QueueLabel.Text = queue.Value.. "/20 in queue"
				guiFrame.TutorialButton.Visible = false
				guiFrame.ShopButton.Visible = false
				guiFrame.QueueButton.Visible = false
				if queue.Value == 20 then
					task.wait(1)
					teleportService:Teleport(14453697332, player)
					queue.Value = 0
					guiFrame.QueueLabel.Text = queue.Value.. "/20 in queue"
					script.CountdownValue.Value = 30
					guiFrame.Countdown.Text = script.CountdownValue.Value
					guiFrame.Countdown.Visible = false
				end
				if queue.Value == 10 then
					guiFrame.Countdown.Visible = true
					guiFrame.Countdown.Text = script.CountdownValue.Value
					for i = 1, 30 do
						script.CountdownValue.Value = script.CountdownValue.Value - 1
						guiFrame.Countdown.Text = script.CountdownValue.Value
						task.wait(1)
					end
					if script.CountdownValue.Value == 0 then
						queue.Value = 0
						guiFrame.QueueLabel.Text = script.Queue.Value.. "/20 in queue"
						script.CountdownValue.Value = 30
						guiFrame.Countdown.Text = script.CountdownValue.Value
						guiFrame.Countdown.Visible = false
						teleportService:Teleport(14453697332, player)
					end
				end
			end
		end)
	end
end)

edit: forgot to paste the script from the local script, but its just the mousebutton1click signal and fireserver function anyway

1 Like

maybe try this:

if script.Queue.Value == 20 then
	task.wait(1)
	script.Queue.Value = 10
	guiFrame.QueueLabel.Text = script.Queue.Value.. "/20 in queue"
	script.CountdownValue.Value = 0
	guiFrame.Countdown.Text = script.CountdownValue.Value
	guiFrame.Countdown.Visible = false
end
if script.Queue.Value == 10 then
	guiFrame.Countdown.Visible = true
	guiFrame.Countdown.Text = script.CountdownValue.Value
	for i = 1, 30 do
		if script.CountdownValue.Value == 0 then
			break
		end
		script.CountdownValue.Value = script.CountdownValue.Value - 1
		guiFrame.Countdown.Text = script.CountdownValue.Value
		task.wait(1)
	end
	if script.CountdownValue.Value == 0 then
		script.Queue.Value = 0
		guiFrame.QueueLabel.Text = script.Queue.Value.. "/20 in queue"
		script.CountdownValue.Value = 30
		guiFrame.Countdown.Text = script.CountdownValue.Value
		guiFrame.Countdown.Visible = false
		teleportService:Teleport(14453697332, plr)
	end
end
1 Like

I found a mistake in mine I edited it out

as @12312ababc has just changed. I don’t know why if you press the button twice you will get teleported ( queue value equal to 20)
i think what you meant to do is while true do instead of if true do
in that case entirely remove queue.Value== 10 and anything inside of that check

I think I found the mistake. dont use my eariler one. use this:

local teleportService = game:GetService("TeleportService")

game.Players.PlayerAdded:Connect(function(plr)
	if true then
		local guiFrame = plr:WaitForChild("PlayerGui"):WaitForChild("QueueGui").QueueScreenFrame
		guiFrame.QueueButton.MouseButton1Click:Connect(function()
			local play = {
			slot1 = ""
			slot2 = ""
			}
			if true then
				local player = guiFrame.Parent.Parent.Parent
				script.Queue.Value = script.Queue.Value + 10
				guiFrame.QueueLabel.Text = script.Queue.Value.. "/20 in queue"
				guiFrame.TutorialButton.Visible = false
				guiFrame.ShopButton.Visible = false
				guiFrame.QueueButton.Visible = false
				if script.Queue.Value == 20 then
					play["slot2"] = plr
					task.wait(1)
					script.Queue.Value = 10
					guiFrame.QueueLabel.Text = script.Queue.Value.. "/20 in queue"
					script.CountdownValue.Value = 0
					guiFrame.Countdown.Text = script.CountdownValue.Value
					guiFrame.Countdown.Visible = false
				end
				if script.Queue.Value == 10 then
					if play["slot1"] == "" then
						play["slot1"] = plr
					end
					guiFrame.Countdown.Visible = true
					guiFrame.Countdown.Text = script.CountdownValue.Value
					for i = 1, 30 do
						if script.CountdownValue.Value == 0 then
							break
						end
						script.CountdownValue.Value = script.CountdownValue.Value - 1
						guiFrame.Countdown.Text = script.CountdownValue.Value
						task.wait(1)
					end
					if script.CountdownValue.Value == 0 then
						script.Queue.Value = 0
						guiFrame.QueueLabel.Text = script.Queue.Value.. "/20 in queue"
						script.CountdownValue.Value = 30
						guiFrame.Countdown.Text = script.CountdownValue.Value
						guiFrame.Countdown.Visible = false
						teleportService:Teleport(14453697332, play)
					end
				end
			end
		end)
	end
end)
1 Like

tried it, now the countdown never appears and neither player gets teleported + it still acts client-sided for player 2

edit: will use the fixed version

nvm this one also has a mistake Im gonna recheck until it works

2 Likes