So I made this tool that makes a ray to detect which block the player is standing on then copies the block’s color and material to the tool handle but if the player dies the ray doesn’t run. What can I do? This is the script:
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
local LiquidV = script.Parent.Handle:FindFirstChild("HasLiquid")
script.Parent.Activated:Connect(function()
if LiquidV.Value == false then
LiquidV.Value = true
local newRay = Ray.new(HumanoidRP.CFrame.p, Vector3.new(0,-1,0).unit * 10)
local Hit = game:GetService("Workspace"):FindPartOnRay(newRay, Character)
local HitBrickColor = Hit.BrickColor
local HitColor3 = Hit.Color
local HitMaterial = Hit.Material
if Hit then
script.Parent.Handle.Liquid.Transparency = 0
script.Parent.Handle.Liquid.Color = HitColor3
script.Parent.Handle.Liquid.Material = HitMaterial
end
elseif LiquidV.Value == true then
print("Has Liquid. Play anim")
LiquidV.Value = false
script.Parent.Handle.Liquid.Transparency = 1
end
end)
If the script is in starterCharacterScripts or made the child of the character another way put the script in starterPlayerScripts instead because when the player dies(character is removed) the script is destroyed.
I still don’t see the other problem, what about it isnt working? but either way when the character dies the script is going to be destroyed and can’t run.