Multiple issues with an obby script

I have a few problems with some scripts in my obby game, and was hoping to find a solution here.

Issue #1 (gyazo gif)

One of the main problems is how the up hide ui button I have does not work with mobile devices as shown in the gif. There is no output, the buttons are scaled correctly, so there has to be something I’m missing. It works with other UIs and on desktop (as shown here (gyazo gif)).

Another issue I came across is that I can’t make the player load in rather than having a slow reset process. I have it so that when you click the r key, you reset to your previous checkpoint. This was also going to have a mousebutton1click function to it so it is compatible with mobile users. Though, I can’t get that far, because when I set it so that it loads the player, I get this:

It is a localscript in startercharscripts. If I put it as a regular script or anywhere else, it will error saying attempting to index nil with “humanoid” OR something similar.

I am wondering how I can make a compromise so that all of the following occur:
– The reset button works with mousebutton1click
– The reset button works with R
– You load in rather than die slowly (meaning LoadCharacter() instead of hum.health = 0)

Please provide suggestions and other solutions in the replies below.

you have to load with a server script not locally

Figured that out already. But then I can’t make it so that when you press r or load click the button it loads, since that has to be done locally.

Add a remote event in replicatedstorage called ResetCharacter, then, add a serverscript that contains this:

game.ReplicatedStorage.ResetCharacter.OnServerEvent:Connect(function(Player)
   Player:LoadCharacter()
end)

In the localscript:

ButtonInstance.MouseButton1Click:Connect(function()
   game.ReplicatedStorage.ResetCharacter:FireServer()
end)
game:GetService("UserInputService").InputBegan:Connect(function(Input, GameProccessed)
   if Input.KeyCode == Enum.KeyCode.R and GameProccessed == false then
      game.ReplicatedStorage.ResetCharacter:FireServer()
   end
end)

You can view more about remote events here: Remote Functions and Events

Okay, it works!

Also if you have a solution to this, please let me know!

Are you using scale for the Gui? Maybe, when you change the screen size, the button moves from the position you’re clicking. Is the button invisible?

I scale the guis by setting their size to 0,0,0,0 upon creating them, making them automatically scale.

I used roundify to curve the edges and yes the button itself is invisible.

Can we see the script for the hide ui button?

You can set the transparency of the button to 0.5 and test if it doesnt move from their original position, also, check if there isn’t another UI object blocking it

The script works and uses mousebutton1click, and thats all you really should need to know

1 Like

I don’t think it’s necessary because it works on PC

2 Likes

Does not work. And there is an image but that shouldn’t be a problem since it’s also scaled.

Check if the ZIndex of the image is less than the ZIndex of the button, it’s a property of all UI objects. If it isn’t, the image is probably preventing the button from get clicked

I made it so that they have the same zindex, and it works!

Testing it out now with multiple people, and it does not work for anyone but the first person to join. Why is that? Can you fix this?

Did you got any error in /console? Did you add something else to the script?

It says “stagegui is not a member of player.playergui”
And no I did not.

Can you show the entire script?


^local

image
^serverscript

I have 2 buttons (one for pc, one for mobile) because one of them has Reset ( R ) and one just has Reset (for mobile) which are scripted and work.

Here is the error, when the player joins, the localscript loads before the StageGui, sending an error because still doesnt exists (didnt load yet).

You can fix this by replacing:

game.Players.LocalPlayer.PlayerGui...--rest of the code 

for:

game.Players.LocalPlayer.PlayerGui:WaitForChild("StageGUI")...--rest of the code*
1 Like