Issues when waiting for parts to load

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

You may have StreamingEnabled set to true. This only loads parts when the player is near enough to them. Disabling it will load all parts, not matter how far away they are, but will increase memory usage.
On a side note, you may want to make that kill script server-sided. An exploiter could just not kill themselves when they touch a part since it’s running on their client.

1 Like

This works I appreciate it, Is there a work around that doesn’t use up as much memory?

Any models with ModelStreamingMode set to Persistent will not stream out, so you could keep StreamingEnabled on, but put any parts you want to stay loaded inside a persistent model.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.