Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

Your variable should be:

local humanoid = char:FindFirstChild("Humanoid")

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

0
still doesnt work jesusbeef 33 — 4y
Ad

Answer this question