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

can someone help with making roblox scripts only work when a certain tool is equipped?

Asked by 3 years ago
01local Player = game:GetService("Players").LocalPlayer
02 
03local rp = game:GetService("ReplicatedStorage")
04local Combat = rp:WaitForChild("Combat")
05 
06local UIS = game:GetService("UserInputService")
07 
08local debounce = false
09local cd = .25
10 
11local currTime = 0
12local prevTime = 0
13local count = 0
14 
15local Equipped = false
View all 56 lines...

I'm trying to get this script to only activate when i have a certain tool equipped help please i already have some code to try to get this to work but it doesn't.

1 answer

Log in to vote
0
Answered by 3 years ago

When a tool is equipped it's always the child of the player equipping it.

Here's the code:

01local Players = game:GetService("Players") --Get player service
02 
03Players.PlayerAdded:Connect(function(player)
04    player.CharacterAdded:Connect(function(character) -- get the in-game player that is not the service
05        local tool = player:FindFirstChild("tool")
06        if tool then
07            -- code
08        end
09    end)
10end)
Ad

Answer this question