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

A little help?

Asked by 10 years ago

I used this script to charge players Points for a sword in my shop.

player = script.Parent.Parent.Parent.Parent.Parent
cost = 5

function checkForword()
    found = false
    for i, v in pairs(player.Backpack:GetChildren()) do
        if v.Name == "Sword" then
            found = true
        end
    end

    for i, v in pairs(player.Character:GetChildren()) do
        if v.Name == "Sword" then
            found = true
        end
    end

    if Found == true then
        return true
    else
        return false
    end
end

script.Parent.MouseButton1Click:connect(function()
    leaderstats = player:FindFirstChild("leaderstats")
    if leaderstas then
        points = leaderstats:FindFirstChild("Points")
        if points then
            hasSword = checkForSword()
            if points.Value >= cost and hasSword == false then
                points.Value = points.Value - cost
                sword = game.Lighting.Sword:Clone()
                sword.Parent = player.Backpack
            end
        end
    end
end)

Whenever I click the button I put the script in, I don't get the sword. Help?

1 answer

Log in to vote
0
Answered by
Noculus 25
10 years ago

I can't answer your question but, just a helpful hint... Instead of using those nasty for loops to check if the character/player has the sword you could do this:

if player.Backpack:findFirstChild('Sword') ~= nil then
    found=true
end

Just cuts down on a couple lines of code. :)

And btw, its nice to tell us if there was an error in the output or not. It narrows down the debug process. :)

0
There is nothing in output. FamousDoge 0 — 10y
0
Ok...Logic error then... Noculus 25 — 10y
0
Oh! I think I found something, on line 18 the word Found is capitalized, unlike all the others. Maybe, that is your problem Noculus 25 — 10y
Ad

Answer this question