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

How can i make a remotevent Refirable?

Asked by 5 years ago

When the client fires the server, it works once but then never fires again. I don't know how to fix this

localscript in starterplayer

local repstorage = game:GetService("ReplicatedStorage")
local clname = script.Parent.Parent.Name
local event = repstorage:FindFirstChild(clname.."_flevent")
local mouse = game.Players.LocalPlayer:GetMouse()

function keyF(key)
    if key == "f" then
    game.ReplicatedStorage[clname.."_flevent"]:FireServer()
    end

end

mouse.KeyDown:Connect(keyF)

normal script in startercharacter

local repstorage = game:GetService("ReplicatedStorage")
local srvname = script.Parent.Name


--start of create spotlight
srvlight = Instance.new("SpotLight",game.workspace[srvname].Head)
srvlight.Enabled = false
srvlight.Range = 33
srvlight.Brightness = 1
--End of create spotlight

--start of create remoteevent
fl_event = Instance.new("RemoteEvent",repstorage)
fl_event.Name = srvname.."_flevent"
--end of create remoteevent

--start of create bool
bool = Instance.new("BoolValue",repstorage)
bool.Name = srvname.."_fleventbool"
--end of create bool

local plrbool = game.ReplicatedStorage[srvname.."_fleventbool"]

function togflash ()
    if plrbool.Value == true then
    plrbool.Value = false
    end
    if plrbool.Value == false then
    plrbool.Value = true
    end
end

repstorage:FindFirstChild(srvname.."_flevent").OnServerEvent:Connect(togflash)

What should happen: when F is pressed, it toggles a bool value. What happens: when F is pressed, it works. When pressed again, it doesn't.

0
Not sure why it's not working, but instead of those if statements, you can just do: plrbool.Value = not plrbool.Value AmazingLeobreaker66 3 — 5y
0
I'm gonna test this in a brand new Place. holadivinus 4 — 5y

Answer this question