So I have a server script and a local script.
the server script will change the player collision to “Players”, then fire a remote event to local script to change the player collision to “LocalPlayer”. but for some reason the client side doesnt change the player collision at all. I tried putting print() everywhere to see the problem but all the script fired correctly in the intended order. what im I missing?
Collision groups can only be created & thus handled by the server.
I found something else that I think is causing the problem.
local script:
server script:
for some reason it print “nil” 3 times, I did check that the server script sent the data correctly or not and it did send the “Char” and not nil
the collision is created on the server. I am just applying it to a player via client side. (I did test on another local script and it work while this one doesnt)
Char should be a reference to the player’s character looking at the script, a1 and a2 are never assigned so them being nil is expected.
Can you explain more? I added print(Char) in the server script and it print the player. So it did sent Char to the client side. but the client still see it as nil. a1 and a2 is just for testing and doesnt matter.
If it prints the character’s name that means the “Char” variable is a reference to the player’s character and not nil.
You could do “Char.Humanoid.WalkSpeed = 30” for example to locally change the character’s humanoids’ speed.
Then why does the client print nil?
Try adding a slight delay between the loop and the “:FireClient()” call, it’s possible the player’s character model hasn’t yet replicated to the client by time it is called.
task.wait(5)
for example.
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated.RemoteEvent
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
task.wait(5)
remote:FireClient(player, character)
end)
end)
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("RemoteEvent")
remote.OnClientEvent:Connect(function(character)
print(character.Name)
end)
This printed my character’s name.