I am a beginner scripter and i need help on changing you hp and speed by clicking a button
How to change your hp and speed by clicking a button???
1 answer
What You Need To Do
So, you want to change your Character's health and speed by a click of a button? This requires deeper knowledge of a few things;
The
MouseButton1ClickEventThe MouseButton1Click event is a "listener" that fires when the client right clicks their mouse.
How Do I Access My Player?
You can easily access your player by indexing
LocalPlayerfrom Players, this is only accessible in LocalScriptsWhere Is Everything Located?
The
HealthandWalkSpeedattributes of your player are located in the Character's Humanoid as Properties
Elaboration
Now that you know these essentials, we can start by defining the Player, with the method stated above.. as well as what you're going to change the WalkSpeed and Health Properties to.
local plr = game.Players.LocalPlayer
local health = 200
local speed = 50
Simple enough, right? Next step is to define your function, that will fire whenever someone clicks your button. Access your Character's Humanoid, and manipulate the WalkSpeed, Health, and MaxHealth Properties. Note: The Health Property can not be higher than the MaxHealth Property.
--Define the function
function onClick()
--Define the humanoid
local hum = plr.Character:FindFirstChild("Humanoid")
--Manipulate the Properties
hum.MaxHealth = health
hum.Health = health
hum.WalkSpeed = speed
end
Now, the final step is to tie your function to an event. Events are listeners that fire whenever a specific action occurs, such as.. someone clicking your TextButton. The event we're going to use is called the MouseButton1Down event, which fires whenever the client right-clicks down the specified gui.
You can tie function to events using something called a connection statement. A connection statement will consist of 4 things;
The Object you're tying the event to
The Event you're trying to the object
The 'connect' method
The function you're wanting to tie to the event
So, if we apply all the credentials to your situation, the data would be;
Your TextButton
The MouseButton1Down Event
The 'connect' method
The function above, 'onClick'
script.Parent.MouseButton1Down:connect(onClick)
Code
So, if we put that all together it would look like this;
local plr = game.Players.LocalPlayer
local health = 200
local speed = 50
function onClick()
local hum = plr.Character:FindFirstChild("Humanoid")
hum.MaxHealth = health
hum.Health = health
hum.WalkSpeed = speed
end
script.Parent.MouseButton1Down:connect(onClick)
1 comment
Epic
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
I wont tell you how to do this but i will tell you the golden rule were not here to create scrips were here to fix them so put a little effort and come back
Please review the ROBLOX Official WIKI, as it may have the answer to your question. :)