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 2 years ago
local Player = game:GetService("Players").LocalPlayer

local rp = game:GetService("ReplicatedStorage")
local Combat = rp:WaitForChild("Combat")

local UIS = game:GetService("UserInputService")

local debounce = false
local cd = .25

local currTime = 0
local prevTime = 0
local count = 0

local Equipped = false

if script.Parent.Equipped:Connect(function()
    Equipped = true
end)

script.Parent.Unequipped:Connect(function()
    Equipped = false
end)

UIS.InputBegan:Connect(function(input,isTyping)
    if isTyping then
        return
    elseif Equipped and input.UserInputType == Enum.UserInputType.MouseButton1 then
        if debounce == false then
            debounce = true
            currTime = tick()

            local passedTime = currTime - prevTime
            if passedTime < 1 then
                --Can Continue the Combat Combo
                count = count + 1
                if count > 4 then
                    count = 1
                end
            else
                --Restarts the combo
                count = 1
            end

            Combat:FireServer(count)

        end
    end
end)

Combat.OnClientEvent:Connect(function()
    prevTime = currTime

    wait(cd)
    debounce = false
end)

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 2 years ago

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

Here's the code:

local Players = game:GetService("Players") --Get player service

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character) -- get the in-game player that is not the service
        local tool = player:FindFirstChild("tool")
        if tool then
            -- code
        end
    end)
end)
Ad

Answer this question