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

How to make a RemoteEvent fire when a button is pressed?

Asked by 5 years ago
Edited by Rare_tendo 5 years ago

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

```lua local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ignitionRequest = ReplicatedStorage:WaitForChild("Ignition")

local ignition = ignitionRequest:InvokeServer()

print("Ignition Started") ``` -- Server

```lua 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.

0
clearer please its mest up starmaq 1290 — 5y
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 starmaq 1290 — 5y
0
Added codeblocks to your code. Remember to use ```lua -- code here ``` to make a codeblock, and it makes your code neater Rare_tendo 3000 — 5y
0
The sound is still playing even when I add script.Parent.On.MouseButton1Click:Connect(function() function to the InvokeServer() roblox245688679934 18 — 5y
0
Got it fixed. roblox245688679934 18 — 5y

Answer this question