New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Why doesn't my remote event change a NumberValue server wide?

Asked by 3 months ago

I've used a remote event which changes a NumberValue which represents the speed of a vehicle in the workspace. It is fired by a local script which passes the speed of the vehicle as the 2nd parameter, this occurs every frame. I want it to change the NumberValue server wide so it can be read by other scripts in the workspace but, this doesn't happen.

--local script

local changeSpeedEvent = seat.Parent.Parent:WaitForChild("SpeedChange")
local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function()
    changSpeedEvent:FireServer(setSpeed)
--Listener script

local SpeedChangeEvent = script.Parent.SpeedChange
local speed = script.Parent.Speed.Value

SpeedChangeEvent.OnServerEvent:Connect(function(player,newSpeed)
    speed = newSpeed
end)

0
Your already a master.. Serpawh -4 — 3mo
0
"changSpeedEvent" line 7 spelt wrong CrazyFlankz 25 — 3mo

1 answer

Log in to vote
0
Answered by
sleazel 679 Moderation Voter
3 months ago
Edited 3 months ago

In server script line 4, you are changing value of local speed variable, instead of referencing NumberValue:

local speed = script.Parent.Speed.Value

What you should do instead is:

--Listener script

local SpeedChangeEvent = script.Parent.SpeedChange
local speed = script.Parent.Speed --copy reference, instead of value

SpeedChangeEvent.OnServerEvent:Connect(function(player,newSpeed)
    speed.Value = newSpeed --set value here
end)

Ad

Answer this question