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

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

Asked by 4 years 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 — 4y
0
"changSpeedEvent" line 7 spelt wrong riceburrito16 40 — 4y

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
4 years ago
Edited 4 years 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