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

What is wrong with this script? [Edited]

Asked by 10 years ago

I looked through everything. What's wrong with it?

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

Thanks in advance for your help!

==EDIT== Okay, so when I checked the Output it said that the error was somewhere in line 2:

    if game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent.Money.Value >= 200 and hit.Parent.Name == script.Parent.Parent.Parent.Owner.Value then

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

Well you checked for the player then decided to access the character to change the money silly(:

Also, you can use a for loop to manipulate the walls for efficiency.

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

script.Parent.Touched:connect(function(hit)
    if db == false then
        db = true
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if plr and plr.Money.Value >= 200 and plr.Name == owner.Value then
            -----------------------------
            plr.Money.Value = hit.Parent.Money.Value - 200
            -----------------------------      
            local walls = script.Parent.Parent.Parent.WallUpgrade2
        -----------------------------
            for i = 1,4 do
                local wall = walls:FindFirstChild("Wall"..tostring(i))
                wall.Transparency = 0
                wall.CanCollide = false --You might want this to be true:P
            end
            -----------------------------
            local TextLabel = script.Parent.Parent.BuyWallsLabel.SurfaceGui.TextLabel
            script.Parent.Transparency = 1
            script.Parent.CanCollide = false
            TextLabel.TextTransparency = 1
            script.Disabled = true
            -----------------------------
        end
        db = false
    end
end)
0
There was an error in line 5. Mind reviewing it. I did and I found nothing. SchonATL 15 — 10y
0
Could you give me the error please? Goulstem 8144 — 10y
0
It just said that it was disconnected because of an exception SchonATL 15 — 10y
0
Oh, sorry I didn't put a debounce. And did you make sure you had enough money? Goulstem 8144 — 10y
View all comments (4 more)
0
Error on line 7 SchonATL 15 — 10y
0
Uhhh.. no? Goulstem 8144 — 10y
0
This is what came up in output: 00:43:52.584 - Money is not a valid member of Player 00:43:52.584 - Script 'Workspace.BuyWalls2.BuyWalls.Script', Line 8 00:43:52.585 - Stack End 00:43:52.585 - Disconnected event because of exception SchonATL 15 — 10y
0
Okay well then you got somethin wrong n0t me. Goulstem 8144 — 10y
Ad

Answer this question