-
What do you want to achieve?
I am trying to find the player who has equipped a tool in my game using thegame.Players.PlayerAdded
event. -
What is the issue?
The script I have written is not finding the player who has equipped the tool. -
What solutions have you tried so far?
I have tried looking for solutions on the DevForum, but haven’t found anything that addresses my specific issue.
This is my current script:
local Tool = script.Parent
local enabled = true
function onActivated()
if not enabled then
return
end
enabled = false
Tool.GripForward = Vector3.new(0,-.759,-.651)
Tool.GripPos = Vector3.new(1.5,-.5,.3)
Tool.GripRight = Vector3.new(1,0,0)
Tool.GripUp = Vector3.new(0,.651,-.759)
Tool.Handle.DrinkSound:Play()
game.Players.PlayerAdded:Connect(function(plr)
local thirst = plr:WaitForChild("playerstats"):WaitForChild("moods"):WaitForChild("Thirst")
local thirstIncrease = 17
-- Increase the player's thirst by the specified amount
thirst.Value = thirst.Value + thirstIncrease
wait(3)
local h = Tool.Parent:FindFirstChild("Humanoid")
if h ~= nil then
if h.MaxHealth > h.Health + 5 then
h.Health = h.Health + 5
else
h.Health = h.MaxHealth
end
end
Tool.GripForward = Vector3.new(-.976,0,-0.217)
Tool.GripPos = Vector3.new(0.03,0,0)
Tool.GripRight = Vector3.new(.217,0,-.976)
Tool.GripUp = Vector3.new(0,1,0)
enabled = true
end)
end
function onEquipped()
Tool.Handle.OpenSound:Play()
end
Tool.Activated:Connect(onActivated)
Tool.Equipped:Connect(onEquipped)
This script always was intended to be a Script
. Thank you for any help!