Hello !!
I’m trying to make a system that kills the player when the part is touched. But unfortunately when trying to wait for the parts to be loaded, it only seems to load the parts when the player is close to it.
when the player gets farther away it no longer attempts to try to load the parts
Example here: (Look at the console for the print statement)
When loading the player next to the spikes it works
But when loading the player farther away from the spikes it no longer tries to load them, although it seems to work every once in a while, unlike when I spawn the player next to the spikes it works every single time
Here’s the script
local spikes = game.Workspace.Spikes:GetChildren()
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local db = false
for _, Data in pairs(spikes) do
repeat
task.wait()
print("DATA IS BEING LOADED")
until Data
end
for i, v in pairs(spikes) do
v.Touched:Connect(function(otherPart)
if otherPart.Parent == char and otherPart.Name ~= "WallJumpHitBox" and not db then
db = true
print("Killing Player")
char.Humanoid.Health = 0
end
end)
end
plr.CharacterAdded:Connect(function()
db = false
end)
This script is located in StarterCharacterScripts
I’m a little confused if anyone knows why please let me know, any help is appreciated