Hi, so I'm trying to make a sound play when a button is pressed, using a RemoteFunction to make it compatible with filtering. While this script does work, the "TextButton" does not and the sound starts playing as soon as I join the server. The path to the TextButton is "script.Parent.On"

-- LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")

  

local ignitionRequest = ReplicatedStorage:WaitForChild("Ignition")


local ignition = ignitionRequest:InvokeServer()

print("Ignition Started")
-- Server
local ReplicatedStorage = game:GetService("ReplicatedStorage")

  

local ignitionRequest = Instance.new("RemoteFunction")

ignitionRequest.Parent = ReplicatedStorage

ignitionRequest.Name = "Ignition"

  

local function onIgnitionRequested(player)

print("Ignition wants to start")

script.Parent.Parent.Parent.Parent.Parent.Parent.ONE.A.ON:Play()

script.Parent.Parent.Parent.Parent.Parent.Parent.TWO.A.ON:Play()

script.Parent.Confirm.BackgroundColor3 = Color3.new(0, 255, 0)

end

  

ignitionRequest.OnServerInvoke = onIgnitionRequested()

Thanks.

5 comments

0

clearer please its mest up

0

the sound is playing as soon as you join because you're firing the :InvokeServer() as soon as the game starts, not inside an event that fires when a buttonis clicked

0

Added codeblocks to your code. Remember to use lua -- code here to make a codeblock, and it makes your code neater

0

The sound is still playing even when I add script.Parent.On.MouseButton1Click:Connect(function() function to the InvokeServer()

0

Got it fixed.