Localscript in tool
local tool = script.Parent local plr = tool.Parent.Parent local mouse = plr:GetMouse() local Crystals = game.Workspace.Crystals local c = plr.Character --here local hum = c.Humanoid --here local storage = game.ReplicatedStorage.CrystalStorage local RegenTime = math.random(5,10) local period = math.random(4,15) game.Workspace.Area.Touched:connect(function(plr) local function onActivate() if mouse.Target.Name == "Crystal" then mouse.Target.Owner.Value = c local a = hum:LoadAnimation(tool.Handle.Animation) a:Play() wait(period) a:Stop() for i,a in pairs(game.Workspace.Crystals:GetChildren()) do if a:IsA("UnionOperation") then if a.Owner.Value == c then a.Parent = storage wait(RegenTime) a.Parent = Crystals a.Owner.Value = nil end end end end end tool.Activated:connect(onActivate) end)
My best guess as to why variable c is returning a nil value is because of certain quirks with accessing the character from the LocalScript. You can read more about that here. It looks like when this script is run the character is not created yet (or that's my best guess).
What I would suggest is not referencing the character and the player by script.Parent references. This makes it harder to understand. We can also steal advice from the article and rewrite your top portion to read.
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local Crystals = game.Workspace.Crystals local c = player.Character if not c or not c.Parent then -- If c is a model that no longer has a parent ... c = plr.CharacterAdded:wait() end
That might be the answer you are looking for.