Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Serversided Health Increase w/ Button?

Asked by 2 years ago

Im trying to increase the Health/MaxHealth values through a GUI Button, but I dont really understand serversided stuff very well. I keep getting FireServer is not a valid member of Script "ReplicatedStorage.Heal_Me".

How do I set this up

0
Is this going to apply to all players or just your player? Also, are you trying to make it like an armor system? So like when you go and pick up the armor, it gives you more health? keram1010 0 — 2y
0
Just the player that presses the GUI, this is just for experimenting, so I might do that, but first I want to first try this out so I understand how it works fireburnpokemon 16 — 2y
0
Alright. keram1010 0 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

You dont need a localscript to fire to a serverscript to change a players health. Because your character is client-sided, if you change any property of your humanoid it will change to the whole server. Ditch that remoteevent and serverscript and just make it really simple. Something like this: (Place this in a localscript inside the button)

local player = game.Players.LocalPlayer
local button = script.Parent
repeat
    char = player.Character
    wait()
until char
local hum = char:FindFirstChildWhichIsA("Humanoid")

button.Activated:Connect(function()
    hum.MaxHealth = hum.MaxHealth + 100
    hum.Health = hum.Health + 100
end)

It would be also great to check the devwiki: They got examples and tutorials on how to use and make things.

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

0
Now if you put this script inside a button, you wont see anything change because the players health changes with the maxhealth. If you remove line 11 you would see that the maxhealth changes hasanchik 49 — 2y
0
Wait i just realized, im wrong, ignore this whole post!!!! hasanchik 49 — 2y
0
yeah, health isnt client sided I dont think. I made it my self, thanks for the help though! fireburnpokemon 16 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Made Remove Event in Replicated Storage named "healthier"

Made a Script in ServerScriptService named "healthier" code:

game:GetService("ReplicatedStorage").healthier.OnServerEvent:Connect(function(Player)
    Player.Character.Humanoid.MaxHealth = Player.Character.Humanoid.MaxHealth + 10

end)

and finally made Button and a child localscript with this code:

 script.Parent.MouseButton1Click:Connect(function()
    game:GetService("ReplicatedStorage").healthier:FireServer()
end)

RemoveEvents were confusing at first, but actually they are pretty easy. Feel free to ask for explanations

Answer this question