Pretty self explanatory. I have a server-sided script placed inside a brick that fires when someone touches the brick. Code:
script.Parent.Touched:Connect(function(hit)
local enemyChar = hit.Parent
local enemyPlr = game:GetService("Players"):GetPlayerFromCharacter(enemyChar)
game.ReplicatedStorage.CameraShakeEvent:FireAllClients(enemyPlr.Name)
print("Event fired")
end)
So I’m sending the enemy Players name to a client sided script placed inside startercharacterscript.
code:
local cameraShakeEvent = game.ReplicatedStorage:WaitForChild("CameraShakeEvent")
local cooldown = 3
cameraShakeEvent.OnClientEvent:Connect(function(plr,enemyPlr)
print(enemyPlr)
for _, v in pairs(game.Players:GetPlayers()) do
if v == enemyPlr then
print("We gott em")
local hum = v.Character:FindFirstChild("Humanoid")
for i = cooldown,0,-1 do
local currentTime = tick()
local shakeX = math.cos(currentTime*10)*.35
local shakeY = math.abs(math.sin(currentTime*10)) *.35
local shake = Vector3.new(shakeX,shakeY,0)
hum.CameraOffset = hum.CameraOffset:lerp(shake,.25)
if i == 0 then
hum.CameraOffset = hum.CameraOffset * .75
end
wait(1)
end
end
end
end)
The output prints nil and I honestly have no clue why. Please help
Thanks in advance!
It is because you are only passing the enemyPlr.Name in the FireAllClients, and you are referencing the second arguement from that event, which is basically nil. So it can be fixed if you replace your cameraShakeEvent’s OnClientEvent to this:
I’m just gonna chime in with some more information on this. If you ever wonder what a function takes for arguments or what the purpose of it is, then the wiki is really helpful. In this case you could simply lookup FireAllClients and you would see examples of it.
--Server
local event = <pathToEvent>
event:FireAllClients("Hello", "World")
--Client
local event = <pathToEvent>
event.OnClientEvent:Connect(function(argument1, argument2)
print(argument1, argument2) -- Will Print Hello World as that is what you pass earlier
end)