Hello! I am working on a murder mystery game. When the game start, the murder will stop moving for 10 seconds, but the output just said, Attempt to index nil with "name"
–This is is the script (Module Script). Error at line 2
local function MurderSetIdle(player)
if player.Name == ServerStorage.Players.Murderer.Value then
local MurderChar = player.Character or player.CharacterAdded:Wait()
local MurderHumanoid = MurderChar:FindFirstChild("Humanoid")
MurderHumanoid.WalkSpeed = 0
MurderHumanoid.JumpHeight = 0
task.wait(10)
MurderHumanoid.WalkSpeed = 16
MurderHumanoid.JumpHeight = 7.2
end
end
–This is where I call the function
local function preparePlayer(player, whichSpawn)
--if player.Name == ServerStorage.Players.Murderer.Value then
-- player.RespawnLocation = spawnLocations.MurderSpawnModel.MurderSpawn
-- player:LoadCharacter()
--else
-- player.RespawnLocation = whichSpawn
-- player:LoadCharacter()
--end
player.RespawnLocation = whichSpawn
player:LoadCharacter()
startSound:Play()
task.spawn(MurderSetIdle, player)
local character = player.Character or player.CharacterAdded:Wait()
-- Give the player a tool
if player.Name == ServerStorage.Players.Murderer.Value then --murderer's knife
local knife = playerWeapons:WaitForChild("Knife"):Clone()
knife.Parent = player.Backpack
elseif player.Name == ServerStorage.Players.Sheriff.Value then --sheriff's gun
playerWeapons:WaitForChild("Gun").Bullets.Value = 8
local gun = playerWeapons:WaitForChild("Gun"):Clone()
gun.Parent = player.Backpack
elseif player.Name == ServerStorage.Players.Healer.Value then --healer's staff
local staff = playerWeapons:WaitForChild("Staff"):Clone()
staff.Parent = player.Backpack
end
end
By using print()
and breakpoints, I knew that the function worked, but the error stop it. I’m pretty bad at explain, but I hope you understand, pls help!
Thanks in advance!