I am trying to achieve a main menu for a simulator that will respawn the player when the player presses the ‘Play’ button.
In my code, I set it so that before the RemoteEvent fires, which triggers the respawn, ResetOnSpawn is disabled, then 2 seconds later it is reenabled. Despite this, it still reappears after I respawn. I added some debugging parts to it, but those did not prove very helpful, as the code ran without error, so I removed them.
Code:
local textButton = script.Parent
local player = game.Players.LocalPlayer
local function onButtonClicked()
game.Workspace.Camera.CameraType = Enum.CameraType.Custom
script.Parent.Parent.Parent.Parent.Sounds.Click:Play()
script.Parent.Parent.Parent.Parent.Enabled = false
script.Parent.Parent.Parent.Parent.ResetOnSpawn = false
game.ReplicatedStorage.RespawnEvent:FireServer()
wait(2)
script.Parent.Parent.Parent.Parent.ResetOnSpawn = true
end
textButton.MouseButton1Click:Connect(onButtonClicked)
If you want me to provide more information, please ask me.
Please excuse my code if there is something you wouldn’t do, I am quite new and don’t do things that efficiently.
You can fix this by setting “ResetOnSpawn” at the properties instead of doing it inside of the script. Don’t ask me why that happen cause i seriously don’t know.
Also just some tips for you:
When working with camera, use: workspace.CurrentCamera because it’s value is the current activate camera, unlike workspace.Camera which is the instance.
Use task.wait() instead of wait(), it’s just better overall.
When changing the cameraType you should always wrap it inside of a repeat. This will make sure that the cameraType changes:
repeat
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
until workspace.CurrentCamera.CameraType == Enum.CameraType.Custom
Alright, i assume that the script you showed before changes the properties of the screenGui.
So you’re going to select that screenGui, and press the ResetOnSpawn button to deactivate it.