How would I make this not spam?

Every time it is rendered or not rendered it will spam

local Camera = game.Workspace.CurrentCamera
local Enemy = game.Workspace.Enemy
game:GetService('RunService').Stepped:Connect(function()
	local Position, PlayerCanSee = Camera:WorldToScreenPoint(Enemy.Position)
	if PlayerCanSee then
			Enemy.Anchored = true
		print("Rendered")
	else
		Enemy.Anchored = false
		print("Not Rendered")
	end
end)

image

Also I think it is messing with the “Enemy.Anchored = true” part.
The part just keeps on floating

Yes it is because you put local of the enemy is the model not the part of the enemy so the enemy won’t get anchored or anything
Local Enemy = game.Workspace.Enemy
instead try (if the enemy you refer to is a model)

local Camera = game.Workspace.CurrentCamera
local Enemy = game.Workspace.Enemy
game:GetService('RunService').Stepped:Connect(function()
	local Position, PlayerCanSee = Camera:WorldToScreenPoint(Enemy.Position)
	if PlayerCanSee then
			Enemy.PrimaryPart.Anchored = true
		print("Rendered")
	else
		Enemy..PrimaryPart.Anchored = false
		print("Not Rendered")
	end
end)

It’s supposed to fall to the ground when not rendered but it still floats (it’s a Part for now)
(And yes I am remaking a NES game)

Do you mind telling me what script you using, mine that i gave you above or yours?

I’m still using mine, I got rid of the “Prints”

When I tried yours:


image

Is that a ViewportFrame? If so, setting the part’s Anchored property to false wouldn’t cause it to move; you would need to do some weird combination of moving it into workspace and back into the viewportframe every frame to give the illusion of movement.

If it’s not a viewportframe, I sadly cannot help you

It’s just a normal Part, I’m just using it as a test

I had a brain fart lol, I found the problem. It’s this:

local Camera = game.Workspace.CurrentCamera
local Enemy = game.Workspace.Enemy
game:GetService('RunService').Stepped:Connect(function()
	local Position, PlayerCanSee = Camera:WorldToScreenPoint(Enemy.Position)
	if PlayerCanSee then
			**Enemy.Anchored = false**
		print("Rendered")
	else
		**Enemy.Anchored = true**
		print("Not Rendered")
	end
end)

Thanks for helping tho! :+1:
(Sorry for wasting your time)

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