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

Problem with my click to mine script?

Asked by 8 years ago

Not sure why, but my code worked before, and now it doesn't. I basically have a tycoon that whenever you buy the mine for free, a model appears (aka the mine) and when you click the button this code is triggered.

I didn't change anything in the mine script. I don't get errors either. My only thoughts are the TeamColor part, that could somehow get messed up for no reason.

Here is a link to the picture of my hierarchy. Picture

For my tycoon, I have a IntValue named "Owner". This changes whenever a player owns the tycoon. Except, it doesn't work. Help?

debounce = false
tycoonOwner = script.Parent.Parent.Parent.Owner.Value

script.Parent.Button.ClickDetector.MouseClick:connect(function(clicker)
    if debounce == false and clicker.Name == tycoonOwner then
        debounce = true
        script.Parent.Button.BrickColor = BrickColor.new("Bright red")

        local part = Instance.new("Part", workspace)
        local cash = Instance.new("IntValue", part)

        cash.Name = "Cash"
        part.FormFactor = "Custom"
        part.BrickColor = script.Parent.Parent.Parent.DropColor.Value
        cash.Value = 1
        part.CFrame = script.Parent.Drop.CFrame
        part.Size = Vector3.new(0.2, 1, 1)
        game.Debris:AddItem(part, 7)
        wait(0.2)
        debounce = false
        script.Parent.Button.BrickColor = BrickColor.new("Bright green")
    end
end)
0
Try putting 'print(clicker.TeamColor)' and see what comes out CaptainRuno 40 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

The first if statement with team colour is probably causing all the trouble, consider checking the player's name instead.

Note: You will want to change how you get the tycoonOwner variable

debounce = false
local tycoonOwner = "Player" -- set this to get the owner name of the tycoon

script.Parent.Button.ClickDetector.MouseClick:connect(function(clicker)
        if debounce == false and clicker.Name == tycoonOwner then
            debounce = true
            script.Parent.Button.BrickColor = BrickColor.new("Bright red")

            local part = Instance.new("Part", workspace)
            local cash = Instance.new("IntValue", part)

            cash.Name = "Cash"
            part.FormFactor = "Custom"
            part.BrickColor = script.Parent.Parent.Parent.DropColor.Value
            cash.Value = 1
            part.CFrame = script.Parent.Drop.CFrame
            part.Size = Vector3.new(0.2, 1, 1)
            game.Debris:AddItem(part, 7)
            wait(0.2)
            debounce = false
            script.Parent.Button.BrickColor = BrickColor.new("Bright green")
        end
end)

Ad
Log in to vote
0
Answered by 8 years ago

I see where you got this, and I used the same tutorial. ...Unless I'm wrong.

In any case, it is likely that the function can't verify that the person is the owner of the tycoon, or it is, and hasn't given you an error (Or at least, I assume you didn't get one.) because the function has determined that whoever has clicked the mine, is not the owner, for whatever reason.

I would use a StringValue for the owners' name, and use the below code.

if debounce == false and clicker.Name == script.Parent.Parent.Parent.tycoonOwner.Value then
    blahblahblahputurcodeherepls
end
0
It changes the value as soon as the person owns the tycoon, it just doesn't work now. UnGenericUser 20 — 8y

Answer this question