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

It don't reacts to my remote event or does my script don't work?

Asked by 5 years ago
Edited 5 years ago
-- local script

game.ReplicatedStorage.PagerSoundEvent.OnClientEvent:connect(function()
    if game.Players.LocalPlayer.Backpack:FindFirstChild("Pager") then
        game.Players.LocalPlayer.PagerSound:Play()
        wait(7)
        game.Players.LocalPlayer.PagerSound:Stop()
        end
end)

so this is in StarterPlayerScripts

-- normalscript in workspace

local player = game.Players.LocalPlayer

if script.Parent.Sound.Value == true then
        game.ReplicatedStorage.PagerSoundEvent:FireServer()
        wait(1)
        script.Parent.Sound.Value = false
    end

This is in workspace but if i turn the sound value on then it don't react without any errors. I used 1 breakpoint at script 2 line 6 but it didn't work? Someone that could help me?

0
There's multiple things wrong with your code: 1.) **A RemoteEvent isn't used for client-to-client communication, it's used for server-to-client communication** 2.) **LocalScripts don't run when parented to workspace** Rare_tendo 3000 — 5y

1 answer

Log in to vote
0
Answered by
Delude_d 112
5 years ago
Edited 5 years ago
  1. A remote event is used only for SERVER to CLIENT communication.
  2. Only ServerScripts run when in workspace.

  3. this should work

-- local script

game.ReplicatedStorage.PagerSoundEvent.OnClientEvent:connect(function()
    if game.Players.LocalPlayer.Backpack:FindFirstChild("Pager") then
        game.Players.LocalPlayer.PagerSound:Play()
        wait(7)
        game.Players.LocalPlayer.PagerSound:Stop()
        end
end)

-- normalscript in workspace
local rep = game:GetService("ReplicatedStorage")

if script.Parent.Sound.Value == true then
        rep:WaitForChild("PagerSoundEvent"):FireClient()
        wait(1)
        script.Parent.Sound.Value = false
    end

0
ServerScripts also run in ServerScriptService, not only in Workspace. saSlol2436 716 — 5y
0
I know... He used localscript in workspace lol. That's why i said only server scripts run in workspace. Delude_d 112 — 5y
Ad

Answer this question