I made a win/loss system, and I created a boolean value (called ‘Win?’). I want to make this value false on death.
I placed the script in StarterCharacterScripts and the value in StarterPlayerScripts.
However, the script does not work when I reset.
It errors: "Workspace.Xiplication.LoseWinOnDied:5: attempt to index nil with ‘Win?’"
The script:
local char = script.Parent
local hum = char:WaitForChild('Humanoid')
function removewin()
game.Players[char.Name]:FindFirstChildWhichIsA('PlayerScripts')['Win?'].Value = false
end
hum.Died:Connect(removewin)
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
function removewin()
local player = game.Players:GetPlayerFromCharacter(character)
if player then
player.PlayerScripts:FindFirstChild("Win?").Value = false
end
end
humanoid.Died:Connect(removewin)
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
function removewin()
local player = game.Players:GetPlayerFromCharacter(character)
if player then
player:WaitForChild("PlayerScripts"):FindFirstChild("Win?").Value = false
end
end
humanoid.Died:Connect(removewin)
That’s strange. Is the PlayerScripts folder named something else, perhaps?
Ive add a WhichIsA() below:
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
function removewin()
local player = game.Players:GetPlayerFromCharacter(character)
if player then
player:FindFirstChildWhichIsA("PlayerScripts"):FindFirstChild("Win?").Value = false
end
end
humanoid.Died:Connect(removewin)
local char = script.Parent
local hum = char:WaitForChild('Humanoid')
function removewin()
if not game.Players.LocalPlayer:FindFirstChild("PlayerScripts") then repeat wait() until game.Players.LocalPlayer:FindFirstChild("PlayerScripts") end
game.Players[char.Name]:FindFirstChildWhichIsA('PlayerScripts')['Win?'].Value = true
end
hum.Died:Connect(removewin)
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
local PlayerScripts = player:WaitForChild("PlayerScripts")
function removewin()
if player then
PlayerScripts:FindFirstChild("Win?").Value = false
end
end
humanoid.Died:Connect(removewin)
Ohh, i see what the problem is now. Just like what @PuHoRkA has said, PlayerScripts are only viewed on the client, not the server. But why do you have the value in PlayerScripts? Are you trying to make if a person dies, only that person loses a win? Or everyone in the server?
I’m trying to make only that person lose their win value. After the game is over, i’ll reset everyone’s win values.
Also I will try to make a script which includes a remote event.
Okay. Then you can really just use a LocalScript for that matter. Remove the current script that is in StarterCharacterScripts, insert a LocalScript in StarterCharacterScripts, and then use this code:
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character) -- you can also get the 'LocalPlayer'
local PlayerScripts = player:WaitForChild("PlayerScripts")
function removewin()
if player then
PlayerScripts:FindFirstChild("Win?").Value = false
end
end
humanoid.Died:Connect(removewin)