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

My script is not working, why?

Asked by 9 years ago

This script was brought up in another question, but it was a while a go and was not given a working answer. Please go over my script and help me figure out what is wrong with it.

local owner = script.Parent.Parent.Parent.Owner
local db = false

script.Parent.Touched:connect(function(hit)
    if db == false then
        db = true
        if hit.Parent.leaderstats.Money.Value >= 200 and hit.Parent.Name == owner.Value then
            -----------------------------
            hit.Parent.leaderstats.Money.Value = hit.Parent.leaderstats.Money.Value - 200
            -----------------------------      
            script.Parent.Parent.Parent.WallUpgrade2.Wall1.Transparency = 0
            script.Parent.Parent.Parent.WallUpgrade2.Wall1.CanCollide = true
            script.Parent.Parent.Parent.WallUpgrade2.Wall2.Transparency = 0
            script.Parent.Parent.Parent.WallUpgrade2.Wall2.CanCollide = true
            script.Parent.Parent.Parent.WallUpgrade2.Wall3.Transparency = 0
            script.Parent.Parent.Parent.WallUpgrade2.Wall3.CanCollide = true
            script.Parent.Parent.Parent.WallUpgrade2.Wall4.Transparency = 0
            script.Parent.Parent.Parent.WallUpgrade2.Wall4.CanCollide = true
            -----------------------------
            script.Parent.Transparency = 1
            script.Parent.CanCollide = false
            script.Parent.Parent.BuyWallsLabel.SurfaceGui.TextLabel.TextTransparency = 1
            script.Disabled = true
            -----------------------------
        end
        db = false
    end
end)

Thank you in advance for your help.

BTW: There is an error in line 7. ;)

0
Well, first of all, if it's a leaderboard you're trying to access, it's not going to be in hit.Parent. It'll be in the player, not the player's character. Tkdriverx 514 — 9y
0
How do I find the player, not the char? SchonATL 15 — 9y
0
I already answered this. And fixed all the errors. Goulstem 8144 — 9y
0
It didn't work. SchonATL 15 — 9y

1 answer

Log in to vote
1
Answered by
Tkdriverx 514 Moderation Voter
9 years ago

You will have to find the player's character:

(put this inside the Touched function)

local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- This method searches Players for a player that has the character model we input.

if player then -- Make sure it exists before we continue. If it doesn't exist, it could break the game.
    local stat = player:findFirstChild("leaderstats"):findFirstChild("Money")

    if stat then
        -- code.
    end
end
0
What code do I put where you say 'code.'? SchonATL 15 — 9y
0
Whatever you want it to do. "stat" can be used as a shortcut to changing the value. (stat.Value = 2 for example) Tkdriverx 514 — 9y
Ad

Answer this question