Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I find or if the player has tool equipped?

Asked by
ElBamino 153
3 years ago
Edited 3 years ago

Hey scriptinghelpers, I'm working on a tool. So the touch is fine everything works but, I'm trying to add or if the player has the tool equipped then to this function (or something like it similar doesn't have to be an if then statement). I don't really know how I would do this or, where I would put this.

This is a script inside of a Handle(part), handle is inside of a tool.

--I have other scripts that give the tool away so, it's constantly changing.
function onTouch(part)
    local character = part.Parent
    local player = game.Players:GetPlayerFromCharacter(character)
    script.Parent.BrickColor = player.TeamColor
    script.Parent.Value.Value = player.TeamColor
end
script.Parent.Touched:Connect(onTouch)

Thanks for the help in advance! I appreciate it.

Thanks Xyternal for the solution! Here's my script I ended up with.

local player = script:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(script.Parent.Parent)
function toolEquipped()
    game.ReplicatedStorage.StringValue.Value = "Equipped"
    game.ReplicatedStorage.BrickColorValue.Value = player.TeamColor
end
function toolUnequipped()
    game.ReplicatedStorage.StringValue.Value = "Unequipped"
end
script.Parent.Equipped:Connect(toolEquipped)
script.Parent.Unequipped:Connect(toolUnequipped)
0
So, I've been testing haven't had any luck. I'm editing my answer to show what I tried. ElBamino 153 — 3y
1
tell me if it works, my answer Xyternal 247 — 3y
1
did it work? Xyternal 247 — 3y
0
Yes thank you! I appreciate it. ElBamino 153 — 3y

1 answer

Log in to vote
1
Answered by
Xyternal 247 Moderation Voter
3 years ago
Edited 3 years ago

My all time favorite is the StringValue. You can make one StringValue in Rep Storage and in your tool, you can add this one script

local script function

function ToolEquipped() 
game.ReplicatedStorage.StringValue.Value = "Equipped"

end

function ToolUnEquipped() 
game.ReplicatedStorage.StringValue.Value = "Uneuipped"

end

script.Parent.Equipped:connect(ToolEquipped)
script.Parent.UnEquipped(ToolUnEquipped)

Server script inside serverscriptservice

local value  = game.ReplicatedStorage.StringValue

while true do
if value.Value = "Equipped" then
--code
else
--code
end
0
Give me one minute, I just woke up. I'm going to test it then let you know if it works! ElBamino 153 — 3y
1
yes ok Xyternal 247 — 3y
0
Sweet, thanks Xyternal works great. I did some editing and I'm going to edit my question to with what I came up with just incase someone else in the future needs it. ElBamino 153 — 3y
1
anytime, my freind Xyternal 247 — 3y
Ad

Answer this question