Activate a script by button

Hey devs, I’m looking for some help with a script. As you can see, I am a builder so I’m not the best scripter. I was able to make up this script, which will shrink the player. I’m wondering how I could make it activated by a button, because I want the player to be able to pick out of three difficulties. The following is for one of the options. It is on a server script in ServerScriptService, and servers are only 1 player.

local shrink_val = 1 -- Starting Value of the shrink
local jump_val = 60 
local walkspeed_val = 16

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)

		local humanoid = character:WaitForChild("Humanoid")
		if player.Character then
			print("Easy mode activated!")
			while wait(25) do -- The time between the shrinks
				if shrink_val > 0.45 then
					shrink_val = shrink_val - 0.025 -- How much it shrinks each time the loop runs
					walkspeed_val = walkspeed_val - 0.7 -- This is what you will have to test yourself
					jump_val = jump_val - 1.75 -- Also this value

					player.Character.Humanoid.HeadScale.Value = shrink_val
					player.Character.Humanoid.BodyDepthScale.Value = shrink_val
					player.Character.Humanoid.BodyWidthScale.Value = shrink_val
					player.Character.Humanoid.BodyHeightScale.Value = shrink_val
					humanoid.WalkSpeed = walkspeed_val
					humanoid.JumpPower = jump_val
					
					print(player.Name.."'s size is "..shrink_val)

				end
			end
		end
	end)
end)

1 Like

First make your part with ClickDetector in
then add this script to it you can use spawn so that it wont yield the script:

local Button = ------your ClickDetector

Button.MouseClick:Connect(function(player)
    local shrink_val = 1 -- Starting Value of the shrink
    local jump_val = 60 
    local walkspeed_val = 16
 
      while wait(25) do -- The time between the shrinks
				if shrink_val > 0.45 then
					shrink_val = shrink_val - 0.025 -- How much it shrinks each time the loop runs
					walkspeed_val = walkspeed_val - 0.7 -- This is what you will have to test yourself
					jump_val = jump_val - 1.75 -- Also this value

					player.Character.Humanoid.HeadScale.Value = shrink_val
					player.Character.Humanoid.BodyDepthScale.Value = shrink_val
					player.Character.Humanoid.BodyWidthScale.Value = shrink_val
					player.Character.Humanoid.BodyHeightScale.Value = shrink_val
					humanoid.WalkSpeed = walkspeed_val
					humanoid.JumpPower = jump_val
					
					print(player.Name.."'s size is "..shrink_val)

				end
			end
   
end)
2 Likes

Thanks for the help, but would it be possible to connect it to a TextButton in a ScreenGui? I’m not sure since it is in a server script.

Actually nevermind, I think I have an idea