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

When I put the MouseButton1Down after already using it it doesn't seem to work as intended?

Asked by 7 years ago
Edited 7 years ago

Here is the code:

`-- In a LocalScript in StarterGui:`

`-- Create ScreenGui`
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

`-- Create TextButton`
local textButton = Instance.new("TextButton")
textButton.Parent = screenGui
textButton.Position = UDim2.new(0, 25, 0, 50)
textButton.Size = UDim2.new(0, 150, 0, 50)
textButton.BackgroundColor3 = BrickColor.White().Color

textButton.Text = "Synch"
textButton.Parent.Enabled = false

`--First use`
textButton.MouseButton1Down:connect(function()
     game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
    if textButton.Parent.Enabled == true then
        textButton.Text = "De-Synch"
    end
end)

`--Second use`
    textButton.MouseButton1Down
:connect(function()
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
    end)

So what I'm trying to do is for the Gui button to go from sync to de-sync and immobilize player then once you click de-sync it will give the player movement back

The code to go with it is stapled to a part that when touched makes the Gui enabled = true therefore making it say de-sync

1 answer

Log in to vote
0
Answered by 7 years ago
`-- In a LocalScript in StarterGui:`

`-- Create ScreenGui`
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

`-- Create TextButton`
local textButton = Instance.new("TextButton")
textButton.Parent = screenGui
textButton.Position = UDim2.new(0, 25, 0, 50)
textButton.Size = UDim2.new(0, 150, 0, 50)
textButton.BackgroundColor3 = BrickColor.White().Color

textButton.Text = "Synch"
textButton.Parent.Enabled = false

textButton.MouseButton1Click:connect(function()
    if textButton.Text == "Synch" then
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
        textButton.Text = "De-Synch"
    else
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
        textButton.Parent.Enabled = false
        textButton.Text = "Synch"
    end
end)
0
Here is how I fixed it/ answer if anyone has a similar problem HaloStorm22 10 — 7y
Ad

Answer this question