So, what I want to achieve is to make a button on the workspace which the player can press on it.
This is what I have in a local script located in StarterPlayerScripts
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local folder = playerGui:WaitForChild("RefreshGlobalLeaderboard")
local donateButton = folder:WaitForChild("DonateButton"):WaitForChild("ImageButton")
-- I clicked on that button, the "HELLO" text never print out
donateButton.MouseButton1Up:Connect(function()
print("HELLO")
end)
You can see that the adornee have set to object in workspace and the Active has tick on. (sorry it has the same name it might cause confusion but I really set it to the DonateButton on workspace, still it’s not work)
The only twist is that when I changed the event to
-- I move my mouse hover the button and it print "HELLO"
donateButton.MouseEnter:Connect(function()
print("HELLO")
end)
It’s work, and that’s made me more frustrating, please if anyone knows what the problem is.
Edit: This event does not work anymore after player reset their character even I turned off the ResetOnSpawn on surface gui which is kinda weird
I try using your code it’s working perfectly fine for me are you sure nothing blocking the surface gui? (Transparency part include) for it’s not working when respawn try restart script when character respawn (not sure why this happened)
(Not sure if streamable died again)
Here code i used:
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local donateButton = playerGui:WaitForChild("DonateButton").ImageButton --Surface Gui in PlayerGui
donateButton.MouseButton1Up:Connect(function()
print("Mouse 1 Up")
end)
donateButton.MouseEnter:Connect(function()
print("Mouse Entered")
end)
player.CharacterAdded:Connect(function()
script.Disabled = true
task.wait()
script.Disabled = false
end)
Wow, thank you for your reply. This code solves the respawn problem perfectly (but idk why it works as well might be the Roblox problem maybe?)
However, the main problem remains the same. There’s no other transparency object blocking the way. I’m not sure is it because I bind the ContextActionService:BindAction() with the Enum.UserInputType.MouseButton1? I really wish it’s not cuz that bind action is really important for my game. But if it’s because of that I might need to think of a better way to display the button on workspace. If you happen to know a better solution please recommend me, anyway thanks for your testing.
Yeah, I not sure is it the cause of this problem? The other UI from screen gui is working fine except this surface gui so I not entirely sure that is the problem.
local function onDonateButtonClicked(actionName, inputState)
if inputState == Enum.UserInputState.End then --End = mouse up
print("Mouse 1 Up for donate")
end
end
donateButton.MouseEnter:Connect(function()
print("Mouse Entered")
--Temp bind mouse event
ContextActionService:BindAction("Mouse1Donate", onDonateButtonClicked, true, Enum.UserInputType.MouseButton1)
end)
donateButton.MouseLeave:Connect(function()
--unbind temp mouse event
ContextActionService:UnbindAction("Mouse1Donate")
end)
We bind “Mouse1Donate” when mouse is enter the surface gui in unbind it when leave surface gui
[important note]
the action name you bind for “Mouse1Donate” shouldn’t same with other action name