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

This local script doesn't function when is a child of an instanced part?

This server script is activated when clicked. When clicked, it will spawn a new part and have a localscript inside of it. But the localscript doesn't work?

When i look at the workspace the localscript is there inside the part, but it doesnt work.

Server Script:

part = script.Parent

part.ClickDetector.MouseClick:Connect(function(player)
	repeat wait() until player.Character
	
	local newpart = Instance.new("Part",workspace)
	newpart.Size = Vector3.new(3,3,3)
	newpart.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,4,0)
	
	newpart.Touched:Connect(function(hit)
	local Reward = script.Reward:Clone()
	if hit then
		Reward.Parent = newpart
		Reward.Disabled = false
		wait(0.1)
		Reward:Destroy()
		end
	end)
end)

Local Script:

local player = game.Players.LocalPlayer
local part = script.Parent

part.Touched:Connect(function(hit)
	local char = hit.Parent
	local humanoid = char:WaitForChild("Humanoid")
	print("Touched!")
end)

1 answer

Your variable should be:

local humanoid = char:FindFirstChild("Humanoid")

Since that is how Humanoid is located, that will make your script work now.

1 comment

0

still doesnt work

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