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)
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