#Health script moved to a server script, but it just shows 'Label'

1 messages · Page 1 of 1 (latest)

tiny basalt
#

so im trying to move my health script from a local script in StarterPlayerScripts, over to a server script in ServerScriptService. because its kinda unsafe for the client to be handling the numbers right? also im gonna do this for my stamina/sprinting script aswell.

HealthManager ServerScript:

game.Players.PlayerAdded:Connect(function(player)
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character:WaitForChild("Humanoid")
    local RunService = game:GetService("RunService")
    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local TakeDamage = ReplicatedStorage.TakeDamage
    local UpdateHealthUI = ReplicatedStorage.UpdateHealthUI
    humanoid.MaxHealth = 200
    humanoid.Health = 200
    local Health = humanoid.Health
    local MaxHealth = humanoid.MaxHealth

    RunService.Heartbeat:Connect(function(deltaTime)
        Health = humanoid.Health
        MaxHealth = humanoid.MaxHealth
        UpdateHealthUI:FireClient(player, Health, MaxHealth)
    end)

end)

#

then my local script that is supposed to manage the gui is

#
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateHealthUI = ReplicatedStorage.UpdateHealthUI
local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui

UpdateHealthUI.OnClientEvent:Connect(function(player, Health, MaxHealth)
    playerGui.HealthGui.HealthFrame.HealthBar.Size = UDim2.new(math.clamp(Health / MaxHealth,0,1),0,1,0)
    playerGui.HealthGui.HealthFrame.HealthLabel.Text = tostring(math.floor(Health)) .."/".. tostring(math.floor(MaxHealth))
end)
undone gazelle
#

Yk that the client can see their own health right

tiny basalt
#

yh

#

itd be better to store everyones health on the server right

#

since exploits could alter the client

#

yknow what i probally wont have to worry about exploiters theres only like 20ish people waiting for this lol

sacred lanceBOT
#

studio** You are now Level 2! **studio

sterile goblet
#

you dont need to fire a remote to the client to do it

tiny basalt
#

im pretty new to studio, so do i just fire that like i would a remoteevent

sterile goblet
#

no it does it automatically when the humanoids health changes

all you need is
Humanoids.Health = 92

then it fires on the server and the client

tiny basalt
#

put that in the one that changes gui?

sterile goblet
#

no that part can be on the server

sterile goblet
tiny basalt
#

ah ok thx

sterile goblet
#

np