Hi, I have a script that needs to know the player’s position at all times so when the player dies and respawns the script goes “Oh, where did the player go?!?! Welp, I’mma stop working now”.
What am I doing wrong:
local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local ded = false
hum.Died:Connect(function()
ded = true
wait(4)
ded = false
end)
local RunSerivce = game:GetService("RunService")
local function Update()
if ded == false then
game.ReplicatedStorage.GameFunctions.Update_Render:Fire()
end
end
RunSerivce:BindToRenderStep("RenderSys", 1, Update)
local player = game:GetService('Players').LocalPlayer
local connection
local char
local hum
if char then
char = player.Character
hum = char:FindFirstChildOfClass('Humanoid')
connection = hum.Died:Connect(function()
game:GetService('ReplicatedStorage').GameFunctions.Update_Render:Fire()
end)
end
player.CharacterAdded:Connect(function(char)
if connection then
connection:Disconnect()
end
char = char
hum = char:FindFirstChildOfClass('Humanoid')
connection = hum.Died:Connect(function()
game:GetService('ReplicatedStorage').GameFunctions.Update_Render:Fire()
end)
end)
Apologies for spoon-feeding but there was just so much wrong with this, along with unnecessary events.
Hi, thanks for replying, sorry I forgot to say I have another script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local RunSerivce = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local RenderCache = ReplicatedStorage:WaitForChild("RenderCache")
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local RenderDistance = 500
local Render = Workspace.Map:WaitForChild("StreetLights")
local Parts = {}
local db = false
function Scan()
if db == false then
print("Yessir")
db = true
for _, Object in next, Render:GetChildren() do
table.insert(Parts, Object)
Object.Parent = RenderCache
end
end
end
function GetPart (Object)
if (Object:IsA("BasePart")) then
return Object
else
for _, Obj in next, Object:GetChildren() do
return GetPart(Obj)
end
end
return nil
end
function Update()
if HumanoidRootPart then
for _, v in next, Parts do
local Part = GetPart(v)
if (Part) then
local Distance = (Part.CFrame.p - HumanoidRootPart.CFrame.p).Magnitude
Distance = math.floor(Distance + 0.5)
if (Distance <= RenderDistance) then
v.Parent = Render
else
v.Parent = RenderCache
end
end
end
end
end
Scan()
game.ReplicatedStorage.GameFunctions.Update_Render.Event:Connect(function()
Update()
end)
It changed something, so now, as you see in the second script I sent that it puts some models into a folder in replicated storage but only when the player is far away. Now it disapears forever
Wait!
I noticed in the script you gave me it didn’t have a loop:
local player = game:GetService('Players').LocalPlayer
local connection
local char
local hum
if char then
char = player.Character
hum = char:FindFirstChildOfClass('Humanoid')
end
player.CharacterAdded:Connect(function(char)
print("YES")
if connection then
connection:Disconnect()
end
char = char
hum = char:FindFirstChildOfClass('Humanoid')
connection = hum.Died:Connect(function()
game:GetService('ReplicatedStorage').GameFunctions.Update_Render:Fire()
end)
end)
Are you able to quickly put a loop in there, I have no idea where to put one