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

If you press on a gui, you go on a team and get walkspeed. How do I do it?

function Click(mouse)
if script.Parent.Parent.Parent.Parent.Parent.TeamColor ~= game.Teams.Pirus.TeamColor then
script.Parent.Parent.Parent.Parent.Parent.TeamColor = game.Teams.Pirus.TeamColor
end
end
Player = script.Parent.Parent.Parent.Parent.Parent
if Player ~= nil then
if Player.TeamColor == game.Teams.Pirus.TeamColor then
    Player.Humanoid.Walkspeed = 100
end
end
script.Parent.MouseButton1Click:connect(Click)

Hello, I am Yeevivor4. What I'm trying to make is that, if you click on a gui, it puts you on a team. What I'm trying to do is that, if you press on that gui and you're on the team, you will get 100 walkspeed. I don't know why it is not working. Can any GUI geniuses help me with this? Also script.Parent.Parent.Parent.Parent.Parent.TeamColor is just the Player's TeamColor.

1 answer

  1. You ended the function early
  2. Using MouseButton1Click requires a down and up, when you only really need a down
  3. It's WalkSpeed not Walkspeed (Yes, it will error)
  4. You could do it all in one 'if statement'
  5. Put it in a LocalScript so you can use game.Players.LocalPlayer

Here's what you need (within a LocalScript which is in the button):

function Click(mouse)
	if game.Players.LocalPlayer.TeamColor ~= game.Teams.Pirus.TeamColor then
		game.Players.LocalPlayer.TeamColor = game.Teams.Pirus.TeamColor
		game.Players.LocalPlayer.Humanoid.WalkSpeed = 100
	end
end
script.Parent.MouseButton1Down:connect(Click)

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