Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why will my sound not play when I hover my mouse?

Asked by 4 years ago
Edited 4 years ago

When I hover my mouse over the button that I've created it will not play the sound effect??

Please help me!


script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Visible = false end) script.Parent.MouseEnter:Connect(function() script.Sound:Play() end)

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

StarterGui acts a container for GUIs, it does not actually represent the authentic household origin of where the active User Interfaces are properly stored.

Upon connection, these GUIs get replicated over to the PlayerGui, to operate with the desired UI, you must always reference it through the authentic location.

local player = game:GetService("Players").LocalPlayer
local playergui = player:WaitForChild("PlayerGui")

local textbutton = script.Parent
local frame = playergui.ScreenGui.Frame

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Visible = false
end)

script.Parent.MouseEnter:Connect(function()
    script.Sound:Play()
end)
0
shall I use serverscriptservice instead or use the GUI's? TgaTheGoldenArmour 15 — 4y
0
No, the code above should work just fine Ziffixture 6913 — 4y
0
Thanks so much! I used ur code and it did not work but than I saw that you used LocalPlayer, it should have been a local script. Thanks for the reply! Also you made a typo on line 5! TgaTheGoldenArmour 15 — 4y
0
Oh thanks! I fix that right away Ziffixture 6913 — 4y
Ad

Answer this question