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

Convert OnClick brick to OnClick TextButton?

Asked by
nicros 165
8 years ago

So ive got this script that atm runs on an OnClicked Brick so when u click the brick it starts my dice rolling game. But im wanting to convert to it to a GUI system instead of through a brick, but im lost on how to do this, here is what ive got

The part im hung up on (i think)

    part = clicked.Character.Head
    local h = part.Parent:findFirstChild("Humanoid")

This script is a product of help from other community members when i was using it for something else, and this part was added to make it work, but this is for a "Part" within workspace, idk how to change it for a GUI within startGui, idk if this matters but figured i would throw it in.

function onTouched(clicked)
    part = clicked.Character.Head
    local h = part.Parent:findFirstChild("Humanoid")
    if (h~=nil) then
            local thisplr = game.Players:findFirstChild(h.Parent.Name)
            if (thisplr~=nil) then
                local stats = thisplr:findFirstChild("leaderstats")
                if (stats~=nil) then
                    local score = stats:findFirstChild("Gold")
                    if (score~=nil) then
                        local Dice = game.Players.Player.PlayerGui.Roller.TextLabel
                        local Rolls = math.random(100)
                        for _ = 1, 1 do

                            print(Rolls)
                            if Rolls >= 55 then
                                score.Value = score.Value + 1
                                Dice.Visible = true
                                Dice.Text = ("You rolled a ") .. Rolls .. ("!")
                                wait(2)
                                Dice.Visible = false
                            else
                                Dice.Visible = true
                                Dice.Text = ("You rolled a ") .. Rolls .. ("...") 
                                wait(2)
                                Dice.Visible = false
                            end
                            wait(.1)
                        end

                    end
                end
            end
        end
    end

script.Parent.ClickDetector.MouseClick:connect(onTouched)

Any help steering me in the right direction is appreciated :)

Answer this question