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

How do I make a button that is a character model?

Asked by 3 years ago

Ok so for context I'm making a script where the intended thing to happen is when you press the button it sets your walkspeed to 0. The catch is, the button is on yourself, aka its a starter character button. This is the script:

local OnButton = script.Parent

function turnOff(plr)
    if game.StarterPlayer.StarterCharacter.Humanoid.WalkSpeed == 16 then
        game.StarterPlayer.StarterCharacter.Humanoid.WalkSpeed = 0 and OnButton.BrickColor == BrickColor.new("Smoky grey")
    end
end

OnButton.ClickDetector.MouseClick:Connect(turnOff)

So how do I go about fixing this script so it is working and clickable? Because right now what it does if you try to click the one on yourself it does nothing, does not consider it a button. But with another player, the clicking icon shows up, but it does not do the thing I wanted it to. Any help?

1 answer

Log in to vote
1
Answered by
megukoo 877 Moderation Voter
3 years ago

If you want this to work, first realize that you're editing the StarterCharacter, not the player's current character. This "current character" can be accessed by doing Player.Character.

Since you have a ClickDetector, this will be relatively simple in converting.

local OnButton = script.Parent

function turnOff(plr)
    -- plr.Character refers to the current player we have, and not the StarterCharacter model.
    if plr.Character.Humanoid.WalkSpeed == 16 then
        -- There was an issue with you using "and" to try and apply assign multiple properties. You don't need to do that. You can put them all on separate lines.
        plr.Character.Humanoid.WalkSpeed = 0 
        OnButton.BrickColor = BrickColor.new("Smoky grey")
    end
end

OnButton.ClickDetector.MouseClick:Connect(turnOff)
0
This makes a lot more sense, and I feel like this should work and it seems like it would, but when I tried it out it hasn't changed anything, let me try with 2 players instead. Maximonist 5 — 3y
0
Yeah I tried it with 2 players and it still didn't work, thanks for trying though. Maximonist 5 — 3y
0
the player's character might be ignored when roblox is checking for a clickdetector. I'm not sure you can get around that if the ClickDetector part is *inside* the player's character. megukoo 877 — 3y
0
Yikes, that sucks. Maximonist 5 — 3y
0
Ok so apparently I can alternatively use "mouse.Target", but I have no idea what it is and how to use it, continuing to search. Maximonist 5 — 3y
Ad

Answer this question