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

Please help how can i change localPlayers health?

Asked by 4 years ago
Edited 4 years ago

on my case i want to use souls value to be the localPlayers heath

Example:

player have 1000 souls then when player have 0 souls the charcter will die and where can i put the script? thanks

sorry but im a newbie.

2 answers

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

Try doing:

Player = game:GetService("Players").LocalPlayer
Humanoid = Player.Character.Humanoid
Health = Humanoid.Health
Souls = Humanoid.Parent.leaderstats.Souls
Health = Souls

That could go in CharacterStarterScripts

Pretty simple and might work.Probally.

0
This will not work since .Health returns its current health and not the actual property. To fix this, just set a variable to the Humanoid then do Humanoid.Health = WhateverHere . poke7667 142 — 4y
0
^^ To clarify, you cannot set a variable to a property because it will just retain the value that the property is set to (and does not update) and not the actual property itself. poke7667 142 — 4y
0
Ew, im new to these scripting stuff, sorry for the incovenience xd, thank you anyway kevinsoaresv 47 — 4y
0
Humanoid = game:GetService("Players").LocalPlayer.Humanoid Health = Humanoid.Health Souls = Souls Health = Souls its not work pukinginakatalaga 0 — 4y
View all comments (10 more)
0
what do you mean "here you place the location of the object" sorry im bad in english pukinginakatalaga 0 — 4y
0
You have to create a NumberValue (Object) in the game/Workspace and say to the game where it is.Example: If placed it in the workspace i should type game.Workspace.Value (Value is the name of the object) in there.And you can create this "NumberValue" object simply by right clicking on something and then inserting it. kevinsoaresv 47 — 4y
0
ok but its a localscript or a normal script? pukinginakatalaga 0 — 4y
0
Local kevinsoaresv 47 — 4y
0
ok i create a NumberValue on workspace the what should i do? pukinginakatalaga 0 — 4y
0
i got this error pukinginakatalaga 0 — 4y
0
19:39:22.532 - Humanoid is not a valid member of Player 19:39:22.533 - Stack Begin 19:39:22.533 - Script 'Workspace.pukinginakatalaga.LocalScript', Line 1 19:39:22.534 - Stack End pukinginakatalaga 0 — 4y
0
i should put some script on NumberValue? pukinginakatalaga 0 — 4y
0
20:24:03.205 - leaderstats is not a valid member of Model 20:24:03.206 - Stack Begin 20:24:03.206 - Script 'Workspace.pukinginakatalaga.LocalScript', Line 4 20:24:03.207 - Stack End pukinginakatalaga 0 — 4y
0
Can i give you my project pls fix it for me much appreciate very much its been more than 2 weeks im stucked on this problem pukinginakatalaga 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

So mine is "game.ServerScriptService.leaderstats" -- the souls value is inside "leaderstats" and the script leaderstats is inside "ServerScriptService"

Humanoid = game:GetService("Players").LocalPlayer.Humanoid Health = Humanoid.Health Souls = game.ServerScriptService.leaderstats -- So is This correct? Health = Souls


This is my leaderstats

local serverStorage = game:GetService("ServerStorage") local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerSave3")

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

local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local souls = Instance.new("IntValue",leaderstats)
souls.Name = "Souls" -- THIS IS THE SOUL IM TALKING ABOUT 
souls.Parent = leaderstats
souls.Value = 0

local strength = Instance.new("NumberValue")
strength.Name = "Strength"
strength.Parent = leaderstats

local rebirth = Instance.new("IntValue",leaderstats)
rebirth.Name = "Rebirth"
rebirth.Parent = leaderstats
rebirth.Value = 0

local dataFolder = Instance.new("Folder")
dataFolder.Name = player.Name
dataFolder.Parent = serverStorage.RemoteData

local debounce = Instance.new("BoolValue")
debounce.Name = "Debounce"
debounce.Parent = dataFolder

local strengthData, rebirthData, soulsData

local success,errormessage = pcall(function()
    strengthData = DataStore:GetAsync("strength-"..player.UserId)
    rebirthData = DataStore:GetAsync("rebirth-"..player.UserId)
    soulsData = DataStore:GetAsync("souls-"..player.UserId)
end)

if success then
    if strengthData then
        strength.Value = strengthData
        rebirth.Value = rebirthData
        souls.Value = soulsData
    end

end

end)

game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() DataStore:SetAsync("strength-"..player.UserId,player.leaderstats.Strength.Value) DataStore:SetAsync("rebirth-"..player.UserId,player.leaderstats.Rebirth.Value) DataStore:SetAsync("souls-"..player.UserId,player.leaderstats.Souls.Value) end) end)

0
There you go i replaced the line in the script i sent you with the info you gave me kevinsoaresv 47 — 4y
0
ok so i put this on CharacterStarterScripts or i should add your line on leaderstats? pukinginakatalaga 0 — 4y
0
Im Very Confused now i dont know where to start im stucked on NumberValue dont know what to do. I need your guide in the beggining to the last pukinginakatalaga 0 — 4y
0
dont worry ill help! RobloxGameingStudios 145 — 4y
View all comments (2 more)
0
can i send you my project and check it? pukinginakatalaga 0 — 4y

Answer this question