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

How can I fix my Worthy Or Not Worthy Script?

Asked by 3 years ago

So I have a script that explodes you if you aren't worthy (if you aren't on the list) and if you are, gives you Excalibur.

Here's my script:

local WorthyUsers = {727003214,895311061,2206010441}
local SwordPrompt = script.Parent



SwordPrompt.Triggered:Connect(function(player)
    for i,v in pairs(WorthyUsers) do
        if v == player.UserId then
            if not player.Backpack:FindFirstChild("Excalibur") and not player.Character:FindFirstChild("Excalibur")  then
                local Excalibur = game.ReplicatedStorage.Excalibur:Clone()
                Excalibur.Parent = player.Backpack
            end
        end

        if v ~= player.UserId then
            local Explosion = Instance.new("Explosion")
            Explosion.Parent = workspace
            Explosion.Position = player.Character.HumanoidRootPart.Position
        end

    end
end)

The Problem Is Even If You Are Worthy After It Checks your UserId to the WorthyUsers Table, it will check all the other ones and since you can't have more than one UserId it also explodes you. Is there any workaround to this?

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
3 years ago

This should work, returning true or false would be more ideal than looping through because with your loop if it's not your id before the loop is finished, it will explode you anyway. However hopefully with this method that I've used it should loop through every ID before it decides to explode you or not.

local worhyUsers = {727003214,895311061,2206010441}
local swordPrompt = script.Parent

local replicatedStorage = game:GetService('replicatedStorage')

function checkIfWorthy(Player)
    for _,id in pairs(worthyUsers) do
        if Player.UserId == id then
            return true
        end -- check userid
    end -- for loop
    return false
end -- function end

function checkForExcalibur(Player)
    local Character = Player.Character or Player.CharacterAdded:Wait()
    if Player.Backpack:FindFirstChild('Excalibur') then
        return true
    elseif Character:FindFirstChild('Excalibur') then
        return true
    end -- checks
    return false
end -- function end

SwordPrompt.Triggered:Connect(function(Player)
    if checkIfWorthy(Player) then
        local checkExcalibur = Player.Backpack:FindFirstChild('Excalibur')
        if not checkForExcalibur(Player) then
            local Excalibur = replicatedStorage.Excalibur:Clone()
            Excalibur.Parent = Player.Backpack
        end -- check for current Excalibur
    else
        local Character = Player.Character or Player.CharacterAdded:Wait()
        local Explosion = Instance.new("Explosion")
                Explosion.Parent = workspace
            Explosion.Position = player.Character.HumanoidRootPart.Position
    end -- check if worthy
end) -- function end
0
Ok i'll try it Littlebigplanet40000 77 — 3y
0
It works Thank You SOOO Much! (I changed it a bit to be more like my scripting) Littlebigplanet40000 77 — 3y
0
Sure, not a problem. Glad I could help. Have a good one! pwx 1581 — 3y
Ad

Answer this question