Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Number Variable passed through Remote Event is nil?

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)

1 comment

0

Remove the Player variable, onclientevent doesn't have a player variable like onserverevent

1 answer

✓ Accepted answer

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!

1 comment

0

Thank you very much! This fixed the whole problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.