Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

`-- 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)

1 comment

0

Here is how I fixed it/ answer if anyone has a similar problem

This discussion is preserved as it was. New answers, comments, and votes are closed.