I have tried many different ways to combat this issue, but I can’t seem to resolve it on my own
The problem that I am having is that I want the point light I scripted into my character activated by a part to stay once the character dies or leaves. Currently the light activates with the part, but after resetting it disappears and when you leave the game it also leaves.
Here is my script so far:
lightpart = game.Workspace.LightPart
light = Instance.new(“PointLight”)
light.Range = 15
light.Brightness = 10
local players = game:GetService(“Players”)
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
lightpart.Touched:Connect(function(hit)
if hit.Parent == character then
light.Parent = character.Head
light.Enabled = true
end
player.CharacterRemoving:Connect(function(character)
if character then
light. Parent = character. Head
light.Enabled = true
end
end)
end)
can anyone tell me where I may be going wrong, there are no errors in output
1 Like
You put it into the characters head while the character is getting removed im pretty sure that WILL always remove it too? Try parenting the light to the workspace instead of the characters head when the character is being removed?
Thank you for replying!! After struggling with this script for about a week I finally came up with this script:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local light = game.ReplicatedStorage.PointLight
local lightoff = game.Workspace.LightOff
local lighton = game.Workspace.LightOn
local humanoid = character:WaitForChild(“Humanoid”)
if character:FindFirstChild(“Humanoid”) then
light.Parent = character:WaitForChild("HumanoidRootPart")
player.CharacterAdded:Connect(function(character)
light.Parent = character:WaitForChild("HumanoidRootPart")
end)
lightoff.Touched:Connect(function(hit)
if character:FindFirstChild("Humanoid") then
light.Enabled = false
end
lighton.Touched:Connect(function(hit)
if character:FindFirstChild("Humanoid") then
light.Enabled = true
end
end)
end)
end
my only concern now is getting the light to save the players data when she or he touches the part, would you have any idea how I could implement this?
You’ll have to look into Roblox data stores, which aren’t the easiest to learn. They save and load player data