I don’t know what I did wrong here:
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
player.msmMoneyValue.Value = 0
game.StarterGui.RobbingGui.Enabled = false
end)
end)
But this was the error I got:
1 Like
DasKairo
(Cairo)
February 26, 2023, 4:35am
#2
How Exactly are you getting the Player, Is it a Server Script?
1 Like
Yes it is. I also put the script in ServerScriptService.
1 Like
Make sure the variable player
is defined in your code.
2 Likes
You never defined the “player” variable
Edit: Someone said the same thing right as I posted; try the code below;
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
player.msmMoneyValue.Value = 0
game.StarterGui.RobbingGui.Enabled = false
end)
end)
end)
3 Likes
p49p0
(Citrullus)
February 26, 2023, 4:50am
#6
attempt to index nil with [index]
is caused because there is no such value named [index] in the current context.
for an example,
mrbeast.marry("me") -- attempt to index nil with "marry"
except if i define it liek this:
local mrbeast = {marry = print} -- adds the table named "mrbeast" to the current context
mrbeast.marry("me") -- outputs "me"
DasKairo
(Cairo)
February 26, 2023, 4:51am
#7
I think you got the wrong topic, lol
p49p0
(Citrullus)
February 26, 2023, 4:52am
#8
Nope, if you were pointing to the mrbeast code, it was only an example. let the op figure it out and learn
1 Like
Btw, hope you’re a woman, or that would be, uh, susy baka lol
2 Likes
p49p0
(Citrullus)
February 26, 2023, 4:55am
#11
you cannot index LocalPlayer from a server script, because the server side is not driven by a player (it will return nil if you access localplayer from the server)
if you want to index LocalPlayer, use it in a localscript.
1 Like
p49p0
(Citrullus)
February 26, 2023, 4:58am
#12
also, if you change a player’s UI in StarterGui, it wont replicate to anyone, except to the server it self. so change the player’s ui by accessing the player’s “PlayerGui” folder
1 Like
So make it a local script instead of a server script?
1 Like
p49p0
(Citrullus)
February 26, 2023, 4:59am
#14
copy paste your script from the image above, then i’ll modify it
1 Like
2112Jay
(2112Jay)
February 26, 2023, 5:02am
#15
Use the </> option Jdlranger
1 Like
local player = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
player.msmMoneyValue.Value = 0
game.StarterGui.RobbingGui.Enabled = false
end)
end)
end)
1 Like
Do you at least know a code that detects when the player dies?
1 Like
Nevermind, I found a solution. Thanks for the help anyway guys!
1 Like
Probably should be something like this:
Code
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
humanoid.Died:Connect(function()
player.msmMoneyValue.Value = 0
player.PlayerGui.RobbingGui.Enabled = false
end)
end)
end)
1 Like