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

How to Call a Player From Tool?

Asked by 6 years ago
Edited 6 years ago

I'm actually using a LocalScript as of right now, but the original script was Server-Side, and I was wondering if we could find a way to convert it to ServerSide, cause either the debounce isn't working, or the script shuts off fully after it is ran a couple of times.

local tool = script.Parent
local handle = tool:WaitForChild("Handle")

print("Loaded") 

local Player = game.Players.LocalPlayer -- player who is holding the tool

repeat wait() until Player.Character

local debounce = true

handle.Touched:connect(function(hit)
       if hit.Parent ~= nil then  -- if what you hit still exists
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- player who touches the handle
        if player and player.Character then 
            local char = player.Character
            local torso = char:FindFirstChild("Torso")
            local hum = char:FindFirstChild("Humanoid")
            if torso and hum and hum.Health > 0 and Player.TeamColor ~= player.TeamColor then
                local dist = (torso.Position - handle.Position).magnitude
                if dist < 5 and debounce then -- an attempt of debouncing lol
                    debounce = false 
                    tool.Parent = char
                script.Disabled=true
                tool.Parent = workspace
                wait() tool.Parent = char
                wait(1.5)
                debounce = true
                end
            wait(1.5)
        end
        script.Disabled=false
        end
    end   
end)

I'm trying to have it so that whenever a player touches the handle, that only the opposite team will be able to grab it, not the exact same team.

Thank you guys so much for your help.

LukeGabrieI aka EnergyBrickz

Answer this question