✓ Accepted answer
Well, there are a couple of problems that you currently have in your code:
referencing the startergui instead of the playergui
trying to access the server storage from a local script
trying to change a value and have the change show up on an object
With that said, we can get to fixing your code
With the first problem, instead of referencing the StarterGui, we need to reference the playerGui which is a child of the player object so we can get it by doing:
local plrgui = game.Players.LocalPlayer.PlayerGui
Now for the second problem, you can circumvent this by simply moving the objects in question from ReplicatedStorage . However, as I don't really know what you are trying to accomplish, but I'd like to leave a warning that setting the position of anything in a local script doesn't change it for the server.
With that said, here is the fixed code:
local plr = game.Players.LocalPlayer
local rep = game.ReplicatedStorage
local plrgui = plr.PlayerGui
script.Parent.Humanoid.Died:Connect(function(dead)
local Life = plrgui.Lives.CurrentLives
local Text = plrgui.Lives.TextLabel
Life.Value = Life.Value - 1
Text.Text = "X " ..Life.Value
print(Life)
if Life.Value < 0 then
rep.Magna.PrimaryPart.Position = Vector3.new(-36.176, 150.398, 851.044)
Life.Value = 3
end
end)
Addition: I realized that I forgot to explain the 3rd problem originally, so here it is:
What you are by defining life and text like that makes them fixed values instead of references
Thus any change to those variable doesn't show up on the textlabel or int value.
I believe incapaxx's answer here provides a great explanation on the topic
Hopefully this helped, have a nice day!
2 comments
Use a Number Value and the .Changed Event
Where is this script located?