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

Number Variable passed through Remote Event is nil?

Asked by
Maxis_s 97
3 years ago

So, I'm trying to pass a number value from the server to the client, but when it goes to the client, it prints out as nil.

Server Script:

local function Explode(Player, ExplosionPart, ExplosionSize, ExplosionTime)
    local Explosion = game.ServerStorage.Explosion:Clone()
    Explosion.Parent = workspace
    Explosion:SetPrimaryPartCFrame(ExplosionPart.CFrame)

    if ExplosionSize > 100 then
        local Time = 5
        game.ReplicatedStorage.Events.ShakeCamera:FireAllClients(Time)
        print("Camera Shake Event Fired")
    end

    --other code
end

Local Script:

local runService = game:GetService("RunService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local function ShakeCamera(Player, Time)
    local function updateBobbleEffect()
        local currentTime = tick()
        local bobbleX = math.cos(currentTime * 10) * 5
        local bobbleY = math.abs(math.sin(currentTime * 10)) * 5

        local bobble = Vector3.new(bobbleX, bobbleY, 0)

        humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.1)
    end

    local CameraShaker = runService.RenderStepped:Connect(updateBobbleEffect)

    wait(Time)

    CameraShaker:Disconnect()
end

game.ReplicatedStorage.Events.ShakeCamera.OnClientEvent:Connect(ShakeCamera)
0
Remove the Player variable, onclientevent doesn't have a player variable like onserverevent Pupppy44 671 — 3y

1 answer

Log in to vote
1
Answered by
Pupppy44 671 Moderation Voter
3 years ago

OnClientEvent does not have a parameter for Player. Player is actually the Time, which is why Time is nil. So remove Player.

local runService = game:GetService("RunService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local function ShakeCamera(Time)
    local function updateBobbleEffect()
        local currentTime = tick()
        local bobbleX = math.cos(currentTime * 10) * 5
        local bobbleY = math.abs(math.sin(currentTime * 10)) * 5

        local bobble = Vector3.new(bobbleX, bobbleY, 0)

        humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.1)
    end

    local CameraShaker = runService.RenderStepped:Connect(updateBobbleEffect)

    wait(Time)

    CameraShaker:Disconnect()
end

game.ReplicatedStorage.Events.ShakeCamera.OnClientEvent:Connect(ShakeCamera)

Hope this helps!

0
Thank you very much! This fixed the whole problem. Maxis_s 97 — 3y
Ad

Answer this question