#whole script wont work

1 messages · Page 1 of 1 (latest)

glacial crypt
#

i want to make a script that detects certain players that join the game, and if it finds that player then they are allowed to use an ability but it wont work at all

local players = game.Players
local uis = game:GetService("UserInputService")


local allowed = false

players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        if player.Name ~= "bonniebunnyomg" then
            allowed = false
            print("not allowed")
        else
            allowed = true
            print("allowed")
        end
    end)
end)

uis.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    if allowed == true and input.KeyCode == Enum.KeyCode.E then
        print("e pressed")
    end
end)

any help?

gilded nova
glacial crypt
#

local

gilded nova
#

What does the logs say, does it print "allowed" or "not allowed", and "e pressed"?

glacial crypt
#

nope

main garnetBOT
#

studio** You are now Level 9! **studio

gilded nova
#

It's probably the PlayerAdded event. Since this is in a localscript, you can omit that entire listener and get the local player's name directly

Assuming the localscript is in StarterCharacterScripts...

Instead of players.PlayerAdded..., do this:

local localPlayer = game.Players.LocalPlayer
local playerName = localPlayer.Name

local allowed = playerName == "bonniebunnyomg" -- Basically means true if playerName is bonniebunnyomg and false otherwise

uis.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    if allowed == true and input.KeyCode == Enum.KeyCode.E then
        print("e pressed")
    end
end)
#

local allowed = playerName == "bonniebunnyomg"

Is the same as

local allowed = nil
if playerName == "bonniebunnyomg" then
    allowed = true
else
    allowed = false
end
glacial crypt
#

ohh

#

i see

#

thanks a lot