So I'm making a game and I'm trying to make a block that when you touch it, a script inserts a point light into the person who touched it's torso, but only that person can see it and no one else can see the light. So far the system I have set up has one server script in the part that, when the player touches the part, a remote event is activated for only their client. Then I have a local script inside the part that waits for the remote event and then is supposed to teleport the player and insert the point light. However, it does nothing. What should I do to fix this and/or how should I go about doing this?
Server Script
local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("playerLight") script.Parent.Touched:connect(function(hit) remote:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent), hit) end)
Local Script
local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("playerLight") remote.OnClientEvent:connect(function(hit) local h = hit.Parent:FindFirstChild("Humanoid") if h ~= nil then hit.Parent:MoveTo(Vector3.new(44.526, -287.545, 1625.304)) local playerLight = script.Parent.PointLight:Clone() playerLight.Parent = hit.Parent.Torso end end)
When the script calls the FireClient method, the first parameter has to be the player object that touched the part
local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("playerLight") script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then remote:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent),hit)--first argument is the player that touched the part, second argument will be the part that touched the brick end end)
now in your local script this is how it looks like
local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("playerLight") remote.OnClientEvent:Connect(function(hit)--notice how at fireclient hit is the second argument, but when its passed to this function hit became the first argument? thats just how it works, if you print hit.Name you will see the name of the part that touched the brick local h = hit.Parent:FindFirstChild("Humanoid") if h ~= nil then hit.Parent:MoveTo(Vector3.new(44.526, -287.545, 1625.304)) local light = Instance.new("PointLight") light.Parent = hit.Parent.Torso end end)
Last point to note, :connect is deprecated, use :Connect instead