if TOUCHED.Parent:FindFirstChildOfClass("Humanoid") then local HUM = TOUCHED.Parent:FindFirstChildOfClass("Humanoid") if HUM.Health <= TOOL.Damage.Value and HUM.Health > 0 then local plr = game.Players.LocalPlayer plr.leaderstats.ELevel.Value = 2 plr.Backpack.DaggerWood:Destroy() local GetDagger = game.ReplicatedStorage.DaggerIron:Clone() GetDagger.Parent = plr.Backpack end
This is the code I am having trouble with. I think the problem is that it can't find the localplayer in a server script, so how would I do that? A few other things to note: A kill upgrades the weapon and this is part of a toolscript. All the variables are working, its that small part that isn't. If you can help, I would greatly appreciate it. Thanks.
Use GetPlayerFromCharacter on the player holding the tool.
if TOUCHED.Parent:FindFirstChildOfClass("Humanoid") then local HUM = TOUCHED.Parent:FindFirstChildOfClass("Humanoid") if HUM.Health <= TOOL.Damage.Value and HUM.Health > 0 then local plr = game:GetService("Players"):GetPlayerFromCharacter(TOOL.Parent) plr.leaderstats.ELevel.Value = 2 plr.Backpack.DaggerWood:Destroy() local GetDagger = game.ReplicatedStorage.DaggerIron:Clone() GetDagger.Parent = plr.Backpack end
in this case, TOUCHED.Parent
is the character, so you can use game.Players:GetPlayerFromCharacter(TOUCHED.Parent)
to get the player
if TOUCHED.Parent:FindFirstChildOfClass("Humanoid") then local HUM = TOUCHED.Parent:FindFirstChildOfClass("Humanoid") if HUM.Health <= TOOL.Damage.Value and HUM.Health > 0 then local plr = game.Players:GetPlayerFromCharacter(TOUCHED.Parent) plr.leaderstats.ELevel.Value = 2 plr.Backpack.DaggerWood:Destroy() local GetDagger = game.ReplicatedStorage.DaggerIron:Clone() GetDagger.Parent = plr.Backpack end
if this helps, please mark the answer as accepted and upvote it