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

Im trying to make a script to check players tool but i get an error?

Asked by 3 years ago
Edited by JesseSong 3 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).
local ToolName = "FlashLight"

while true do
game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        if Player.Backpack:FindFirstChild(ToolName) then
            workspace.BARRIER.Position = Vector3.new(20, 0.5, 45.32)
        else
            workspace.BARRIER.Position = Vector3.new(9.63, 0.5, 45.32)
            end
            wait(1)
            end
    end)
end)



Error-- ServerScriptService.Script:13: Expected ')' (to close '(' at line 5), got 'end' - Studio - Script:13

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

You're missing a few ends in your code. Also, add a wait after or between the loop, so you don't crash. This is the corrected version:

local ToolName = "FlashLight"

while true do
    wait(2)-- change the amount of secs you want it to wait
    game.Players.PlayerAdded:Connect(function(Player)
        Player.CharacterAdded:Connect(function(Character)
            if Player.Backpack:FindFirstChild(ToolName) then
                workspace.BARRIER.Position = Vector3.new(20, 0.5, 45.32)
            else
                workspace.BARRIER.Position = Vector3.new(9.63, 0.5, 45.32
        end
    end)
    end)
end


(Edit: - The other wait between the if statement is redundant, consider removing it!)

Ad

Answer this question