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

A little help?

Asked by 10 years ago

I used this script to charge players Points to purchase 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)

I went into the game, and I didn't get a sword after clicking the button. Also, nothing showed up in output. Any help?

1 answer

Log in to vote
0
Answered by
HexC3D 830 Moderation Voter
10 years ago
player = script.Parent.Parent.Parent.Parent.Parent
cost = 5
found = Instance.new("BoolValue")
found.Parent = game.Workspace
found.Value = false
function checkForword()
  while true do
if player:WaitForDataReady("Backpack").Sword ~= nil
      found.Value = true
wait()
end
        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 found.Value ==   false then
for i = 1,1 do
                points.Value = points.Value - cost
                sword = game.Lighting.Sword:Clone().Parent = player:WaitForChild("Backpack")
 end
           end

        end
    end
end)


I changed it a bit.

0
I tried that, but sword = game.Lighting.Sword:Clone().Parent = player:WaitForDataReady("Backpack") is in red underline. FamousDoge 0 — 10y
0
fixed it it should work now. HexC3D 830 — 10y
0
Still in red underline. And same thing is red underline. found = true is what is red underline. FamousDoge 0 — 10y
0
try again HexC3D 830 — 10y
Ad

Answer this question