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

Inserting a point light into the player's torso that only that player can see?

Asked by 5 years ago

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)
0
connect is deprecated, and use Connect. Also use SetPrimaryPartCFrame instead of MoveTo User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

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

0
You're giving deprecated code at line 13. The parent argument to Instance.new is deprecated. User#19524 175 — 5y
0
ah damn, ill edit it aazkao 787 — 5y
Ad

Answer this question