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

I'm trying to generate a part with Touched When I try this, not appear?

Asked by 3 years ago

What I want to do is that when the player touches the zone a part is generated

local Glitch = Instance.new("Part",game.Workspace)

Glitch.Touched:Connect(function (GlitchMan)
    if game.Players:GetPlayerFromCharacter()then
        Glitch.Position = Vector3.new(2083.119, 2933.307, -35.924)
        Glitch.Size = Vector3.new(41.6, 43, 2)
        Glitch.Parent = game.Workspace

    end
end)


I'm not that good a scripter I'm just starting out, but it would be a great help.

1 answer

Log in to vote
0
Answered by 3 years ago

You can check if a play hit the part by saying:

if GlitchMan.Parent = player.Character then

You should also define player:

local player = game.Players.LocalPlayer

Your script should look something like:

local Glitch = Instance.new("Part",game.Workspace)
local player = game:GetService("Players").LocalPlayer

Glitch.Touched:Connect(function (GlitchMan) -- Glitch man, or in other words the hit part, will be a body part if a player has touched it. (i.e. LeftFoot, HumanoidRootPart, etc.)
    if GlitchMan.Parent == player.Character then --check if the hit part's parent is a character
        Glitch.Position = Vector3.new(2083.119, 2933.307, -35.924)
        Glitch.Size = Vector3.new(41.6, 43, 2)
        Glitch.Parent = game.Workspace

    end
end)
Ad

Answer this question