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

How can I fix this Button script? (edited)

Asked by 9 years ago

So I have this button script:

local owner = script.Parent.Parent.Parent.Parent:WaitForChild("Owner")

function onClicked(playerthatclicked)
    if playerthatclicked == owner.Value then
        local Model = script.Parent.Parent
        Model.OwnerOnlyDoor.BrickColor = BrickColor.new("Really red")
        Model.OwnerOnlyDoor2.BrickColor = BrickColor.new("Really red")
        Model.OwnerOnlyDoor3.BrickColor = BrickColor.new("Really red")
         Model.OwnerOnlyDoor4.BrickColor = BrickColor.new("Really red")
    end
end

script.Parent.closeclick.MouseClick:connect(onClicked)

The almighty Goulstem helped me edit this script to get it to this. There is still the same problem though. Since I want the owner to be the only one able to open/close the OwnerOnlyDoor for the tycoon I added a playerthatclicked script to it. This changed nothing all it did was cause absolutely nothing to happen in the output in-game and in studio even when the owner is the one clicking it. Please help!

2
Did you define playerthatclicked variable? buoyantair 123 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago
local owner = script.Parent.Parent.Parent.Parent:WaitForChild("Owner")

function onClicked(playerthatclicked)
    if playerthatclicked == owner.Value then
        local Model = script.Parent.Parent
        Model.OwnerOnlyDoor.BrickColor = BrickColor.new("Really red")
        Model.OwnerOnlyDoor2.BrickColor = BrickColor.new("Really red")
        Model.OwnerOnlyDoor3.BrickColor = BrickColor.new("Really red")
         Model.OwnerOnlyDoor4.BrickColor = BrickColor.new("Really red")
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)-- I changed this lined.
Ad
Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your Problem

On line 4, you're comparing playerthatclicked with owner.Value. But you never set a parameter for your function named playerthatclicked - it's a nil value. So you'd end up with an error like Attempt to compare with a nil value or something like that.

Also, you neglected to add an 'end' for your if statement on line 4


How to Fix

Just add a parameter to your onClicked function on line 3and name it playerthatclicked.

Add an extra end


Code

local owner = script.Parent.Parent.Parent.Parent:WaitForChild("Owner")

function onClicked(playerthatclicked)
    if playerthatclicked == owner.Value then
        local Model = script.Parent.Parent
        Model.OwnerOnlyDoor.BrickColor = BrickColor.new("Really red")
        Model.OwnerOnlyDoor2.BrickColor = BrickColor.new("Really red")
        Model.OwnerOnlyDoor3.BrickColor = BrickColor.new("Really red")
         Model.OwnerOnlyDoor4.BrickColor = BrickColor.new("Really red")
    end
end

script.Parent.closeclick.MouseClick:connect(onClicked)
0
I am 100% confused now it still doesn't work. Nothing happens even as the Tycoon owner. I am so annoyed! TixyScripter 115 — 9y
0
Is there any errors showing in the output? Goulstem 8144 — 9y
0
Not as I saw there was just nothing at all but let me check again TixyScripter 115 — 9y
0
Well it said nothing. As if you arent the owner even though you are, so it doesnt run the rest on the script TixyScripter 115 — 9y
0
Make sure that your connection statement is indexing a ClickDetector. Goulstem 8144 — 9y

Answer this question