Make an event happen only after player spawns in a particular map

Hello my fellow friends, So I made a lobby where people start in before an intermission. So I have a part that moves and kill player but the part is in a game not in the lobby. I want the part to stay in place until the intermission count down is over then when a player enters the game after the intermission the part will start moving

  1. What is the issue? The part moves before the intermission is over and when the players spawn in the game the part is already gone out of the map.

  2. What solutions have you tried so far? I have tried to make the part go slower so that when the player spawns the part would have the chance to kill players but making the part slow didn’t help because the player would have more time to do the task.

Also I tried to makeup this code but it didn’t work

while true do wait for player spawn() --  In the brackets I add the spawn location "GameSpawn" which didn't work
   then
	
	script.Parent.Size = script.Parent.Size - Vector3.new (20, 0, 20)
	
	end```
1 Like

spawn is used for threading code, unless you created a custom function for it and wait is a global function.
You can use bindable events for this instead of loops

example:

local event = Instance.new("BindableEvent")

event.Event:Connect(function()
 -- round code here
end)

Do you have the brick move immediately?

1 Like

yes it moves when the game start but i want away for it to move after the player spawn.this is the original script – >

while true do wait (1) 
	script.Parent.Size = script.Parent.Size - Vector3.new (20, 0, 20)
	end```
1 Like

Ok, events would be useful here.

To start, what’s the code that you use for intermissions?

Once the intermission is over, you can fire an event:

event:Fire(...) -- "..." would be for the arguments you want to send (if any)

-- but for this example, i'll send "true"
event:Fire(true)

and have the game detect that event and wait for the player to spawn

event.Event:Connect(function(arg)
    -- code to teleport the players to the map (unless you have that in a different script)

    if arg then -- if "arg" is not "nil" or "false"
       -- script that makes the brick spin here
    end
end)

However, the code only works from server script to server script, if you want the client to send requests to the server, you would use RemoteEvents

1 Like

So i haven’t really finished the intermission but this is the start this script is in starterGUI > Timer >local script

local Timer = script.Parent.Timer

script.Parent.Text = Status.Value

Status.Changed:Connect(function()
	script.Parent.Text = Status.Value
end)
2 Likes

Alright, that’s fine

So, in this instance, we would need to use RemoteEvents

local Timer = script.Parent.Timer
local Event = -- path to remote event

local TargetValue = -- the value that the status needs to be to let the game start
script.Parent.Text = Status.Value

Status.Changed:Connect(function()
	script.Parent.Text = Status.Value

    if Status.Value == TargetValue then -- the status is equivalent to the status needed to start the game
        Event:FireServer() -- send a request to the server
    end
end)
-- server script
local event = -- path to remote event

event.OnServerEvent:Connect(function(player) -- the player who fired the remote is automatically passed
 -- code here
end)
1 Like

So do I make the remote event in replicated storage? and add the script in server script service? and this is the finished script for the intermission i was watching The Dev king but the script didn’t work

local intermissionLength = 10
local Inround = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.lobbyspawn
local GameAreaSpawn = game.Workspace.gamespawn


local function Roundtimer()
	while wait() do
		for i = intermissionLength, 1, -1 do
			Inround.Value = false
			wait(1)
			Status.Value = "Intermission: ".. i .." seconds left!"
		end
		for i = roundLength,1, -1 do
			Inround.value = false
			wait(1)
			Status.value = "Game "..i.."seconds left"
		end
	end
end

spawn(roundLength)
)```
2 Likes

Yes, the remote event goes in replicated storage and server script in ServerScriptService

1 Like

ok thank you can you also check the script above

1 Like

Does the script produce any errors? or does it just not work

1 Like

Yeah it doesn’t work, with no errors . Hey if you have time I can invite you in roblox studio and work on the game together

1 Like

Sorry, I can’t go into studio right now, do you update the text at the end of each for loop

example:

for i = intermissionLength, 1, -1 do
   Inround.Value = false
   wait(1)
   Status.Value = "Intermission: ".. i .." seconds left!"

   script.Parent.Text = Status.Value -- placeholder text updater, it might be different in-studio
end
2 Likes

I don’t really know how to do it I will work on. Thank you very very much for your time. Their should be more people like you in devforum

2 Likes