Bindable event not working

Hi,
I want to fix this Bindable event that doesn’t seem to be detected by other local scripts.
I was making a system where the GUI would move based on what platform you were on - mobile to be specific, to ensure that the GUI wasnt covered by the jump button, etc.

After the player’s console was detected in starterplayerscripts, a bindable event was then sent

image

(the statement was switched to computer device to make it easier to test)

local UserInputService = game:GetService("UserInputService")
local event = game:GetService("ReplicatedStorage").GUIPlacement.ChangePlacement

if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
	print("Mobile device")
elseif not UserInputService.TouchEnabled and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	print("Computer device")
	event:Fire()
	print("FIRED")
elseif UserInputService.TouchEnabled and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	print("Computer device with touchscreen")
elseif UserInputService.GamepadEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
	print("Console device")
end

Then, scripts in starter GUI would detect this bindable event

image

local event = game:GetService("ReplicatedStorage").GUIPlacement.ChangePlacement
local frame = script.Parent
local buyGemsButton = frame.BuyGems
local timeText = frame.Time

event.Event:Connect(function()
    print("I got the event!")
	frame.Position = UDim2.new(0.859, 0, 0.103, 0)
	buyGemsButton.Position = UDim2.new(-0.03, 0,0.494, 0)
	timeText.Position = UDim2.new(0.638, 0,1.155, 0)
end)

However, the message “I got the event” would not print and the GUI would not be relocated.

Here is the location of the bindable event:
image

I have tried multiple solutions, such as changing location of bindable event, but it doesn’t work.

Any help on how to fix the bindable event is appreciated!

I suspect the event has fired before the GUI has loaded and started running the script that’s catching the event.
You can test this theory by adding a task.wait(10) right before event:Fire() - This would give the gui a chance to load and run it’s scripts.

2 Likes

Thanks! that works, but are there any ways to not make it wait for a bit before readjusting the position of the GUI?

Would 'WaitForChild:(each gui)" before the script in starterplayerscripts work?

Edit: Yep, wait for child worked!

1 Like