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

How to check if player has tool?

Asked by 9 years ago

So I'm trying to make a class-based game. Right now I'm testing it out on roblox gear.

So. I'm trying to prevent the person from being able to click again if they already have the tool. Here's the script:

textButton = script.Parent
spawns = {game.Workspace.SpawnLocation1 , game.Workspace.SpawnLocation2 , game.Workspace.SpawnLocation3 , game.Workspace.SpawnLocation4}
player = script.Parent.Parent.Parent.Parent
Trowel = game.ReplicatedStorage.ClassicTrowel:Clone() 
already = player.Backpack:FindFirstChild("ClassicTrowel")

if already == nil then
textButton.MouseButton1Down:connect(function()
    script.Parent.Text = "5"
    wait(1)
    script.Parent.Text = "4"
    wait(1)
    script.Parent.Text = "3"
    wait(1)
    script.Parent.Text = "2"
    wait(1)
    script.Parent.Text = "1"
    wait(1)
    player.Character:MoveTo(spawns[math.random(1, #spawns)].Position)
    player.Character.Humanoid.MaxHealth = 200
    player.Character.Humanoid.Health = 200
    Trowel:Clone().Parent = player.Backpack 
    Trowel:Clone().Parent = player.StarterGear
    script.Parent.Text = "Change to Builder"
end)
else return
    end

0
It works already, it just doesn't prevent them from clicking it again SpazzMan502 133 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

Try this..

textButton = script.Parent
spawns = {game.Workspace.SpawnLocation1 , game.Workspace.SpawnLocation2 , game.Workspace.SpawnLocation3 , game.Workspace.SpawnLocation4}
player = script.Parent.Parent.Parent.Parent
Trowel = game.ReplicatedStorage.ClassicTrowel:Clone() 
already = player.Backpack:FindFirstChild("ClassicTrowel")

textButton.MouseButton1Down:connect(function()
if already == nil then
    script.Parent.Text = "5"
    wait(1)
    script.Parent.Text = "4"
    wait(1)
    script.Parent.Text = "3"
    wait(1)
    script.Parent.Text = "2"
    wait(1)
    script.Parent.Text = "1"
    wait(1)
    player.Character:MoveTo(spawns[math.random(1, #spawns)].Position)
    player.Character.Humanoid.MaxHealth = 200
    player.Character.Humanoid.Health = 200
    Trowel:Clone().Parent = player.Backpack 
    Trowel:Clone().Parent = player.StarterGear
    script.Parent.Text = "Change to Builder"
end
end)

If you need a code-block to define "already", this should do.

for _, v in pairs(player.Character:GetChildren()) do
if v:IsA("Tool") then
local already = true
end
end
Ad

Answer this question