Increase Walkspeed If Player Joins Group and clicks button

Hello developers. I’m trying to make a script that adds 50 walkspeed if they click a button and they are in my group. I’ve tried

script.Parent.MouseButton1Down:connect(function()
	
	game.Players.PlayerAdded:Connect(function(newPlayer)
		if newPlayer:IsInGroup(123456789) then                    

			game.Players.PlayerAdded:Connect(function(plr)
				plr.CharacterAdded:Connect(function(char)
					char:WaitForChild("Humanoid").WalkSpeed = char:WaitForChild("Humanoid").WalkSpeed+50
				end)
			end)


		end
	end)
	
end)

and it didn’t work so I’m stuck on what I have to do. Do I have to use a completely different script, or do I need to change a few things?

1 Like

you need local script

local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Down:connect(function()
	if plr:IsInGroup(123456789) then                    
		plr.CharacterAdded:Connect(function(char)
				char:WaitForChild("Humanoid").WalkSpeed += 50
				end)
		end
end)

try to play around with that

1 Like

I would do it in 2 times. Client Side, then Server Side.

You will also need to create a RemoteEvent named “ClickEvent” inside ReplicatedStorage

=> Add this code in the local script under the button

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("ClickEvent")

script.Parent.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer()
end)

=> Create a Script In ServerScriptService

And then in the server script add


local ClickEvent = game:GetService("ReplicatedStorage"):WaitForChild("ClickEvent")

local AddSpeed = 50


ClickEvent.OnServerEvent:Connect(function(Player)
	local Character = Player.Character or Player.CharacterApperanceLoaded:Wait()

	Character.Humanoid.WalkSpeed = Character.Humanoid.WalkSpeed + AddSpeed
end)

And then test it out. Should work for you.

Hope it helped!

1 Like