1 | if TOUCHED.Parent:FindFirstChildOfClass( "Humanoid" ) then |
2 | local HUM = TOUCHED.Parent:FindFirstChildOfClass( "Humanoid" ) |
3 | if HUM.Health < = TOOL.Damage.Value and HUM.Health > 0 then |
4 | local plr = game.Players.LocalPlayer |
5 | plr.leaderstats.ELevel.Value = 2 |
6 | plr.Backpack.DaggerWood:Destroy() |
7 | local GetDagger = game.ReplicatedStorage.DaggerIron:Clone() |
8 | GetDagger.Parent = plr.Backpack |
9 | 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.
1 | if TOUCHED.Parent:FindFirstChildOfClass( "Humanoid" ) then |
2 | local HUM = TOUCHED.Parent:FindFirstChildOfClass( "Humanoid" ) |
3 | if HUM.Health < = TOOL.Damage.Value and HUM.Health > 0 then |
4 | local plr = game:GetService( "Players" ):GetPlayerFromCharacter(TOOL.Parent) |
5 | plr.leaderstats.ELevel.Value = 2 |
6 | plr.Backpack.DaggerWood:Destroy() |
7 | local GetDagger = game.ReplicatedStorage.DaggerIron:Clone() |
8 | GetDagger.Parent = plr.Backpack |
9 | end |
in this case, TOUCHED.Parent
is the character, so you can use game.Players:GetPlayerFromCharacter(TOUCHED.Parent)
to get the player
1 | if TOUCHED.Parent:FindFirstChildOfClass( "Humanoid" ) then |
2 | local HUM = TOUCHED.Parent:FindFirstChildOfClass( "Humanoid" ) |
3 | if HUM.Health < = TOOL.Damage.Value and HUM.Health > 0 then |
4 | local plr = game.Players:GetPlayerFromCharacter(TOUCHED.Parent) |
5 | plr.leaderstats.ELevel.Value = 2 |
6 | plr.Backpack.DaggerWood:Destroy() |
7 | local GetDagger = game.ReplicatedStorage.DaggerIron:Clone() |
8 | GetDagger.Parent = plr.Backpack |
9 | end |
if this helps, please mark the answer as accepted and upvote it