Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can anyone help me solve this problem that player can't MoveTo new part spawned? (SOLVED)

UPDATE: Solved by instead of Remove() the part, setting its Parent = nil works.


When the player clicks on a part, it will walk to that part and get its leaderstat update. When the part is removed and spawned a new one, the player is not walking over to the new part when clicking it. The new part does have the ClickDetector in it. It works for the first initial spawn only. Can you help me see what's wrong here?

local flowers = game.ReplicatedStorage.Flowers.level1:GetChildren()
local selection = math.random(1,#flowers)
local Clone = flowers[selection]:Clone()

local ClickDetector = Instance.new("ClickDetector")
	ClickDetector.Parent = Clone
	ClickDetector.MaxActivationDistance = 500

while true do
	wait(1)
	if Clone.Parent == nil then
	Clone.Parent = workspace.Flowers.level1
	local spawners = workspace.Spawners.level1:GetChildren()
	local spawnSelection = math.random(1,#spawners)
	local spawner = spawners[spawnSelection]
	Clone.CFrame = spawner.CFrame + Vector3.new(math.random(-5,5),1,math.random(-5,5))
	
	ClickDetector.MouseClick:Connect(function(playerWhoClicked)
	local target = Clone
	playerWhoClicked.Character.Humanoid:MoveTo(target.Position,target)
	wait(1)
	target:Remove()
	local flowerValue = playerWhoClicked.leaderstats.Flowers
	local coinsValue = playerWhoClicked.leaderstats.Coins
	flowerValue.Value = flowerValue.Value + 1
	coinsValue.Value = coinsValue.Value + 5
	end)
	
	end
end

3 comments

0

I'm not good in MoveTo, but I do know, for a fact that the player(Humanoid) needs to see the brick after it has spawned. Try putting in a Wait in somewhere.

0

Putting a wait right after it spawns a new one doesn't work. Putting a wait after the click function end doesn't work, neither. I can't put the local ClickDetector inside the loop because when I do that, it multiplies inside the part.

0

I also set debounce before and after the player clicks the part, but that doesn't solve the problem.

1 answer

Since I cannot find the problem in this script yet, I just make an alternative script by putting the part in Workspace instead of cloning it from ReplicatedStorage. And instead of removing it, I just alter its Transparency and debounce then relocating it to another random position before reappearing again.

1 comment

0

solved it by setting its Clone.Parent = nil instead of Remove().

This discussion is preserved as it was. New answers, comments, and votes are closed.