Issue with ResetOnSpawn not working correctly (solved)

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.

1 Like

What happens if you do not set ResetOnSpawn back to true?

The problem remains despite that, as it keeps giving me the GUI after I respawn.

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.

image


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

Hi, just a quick question.

By ‘changing it at the properties’, could you elaborate on this? I don’t understand how I would do this outside of the studio.

Also, thanks for the tips, I will remember these!

Can you send a screenshot of your studio? Or the explorer ( the place where you select instances )

Hi, I had to split the images because my screen isn’t big enough to fit all of them, but here you go.

The script that has the logic that is causing the problem is the LocalScript inside the button located at the ‘Play’ Frame

image

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.

After deactivating it, go back to the script and remove this part:

wait(2)
script.Parent.Parent.Parent.Parent.ResetOnSpawn = true

Oh, now I understand what you mean!

Thank you for your support, I will look into the problem in the future.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.