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

Why isn't this script working?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I am trying to make a script when a player touched a certain "part" it will clone then destroy but when I end the script it says I need to correct it.

SCRIPT:

if game.Players.Player1.Humanoid.onTouched then game.Workspace.Part:Clone end then wait(10) game.Workspace.Part:Remove() end

2 answers

Log in to vote
2
Answered by 10 years ago

Touched is an event, and it needs to be treated as such. Here's a quick rundown of how events work:

function onTouched(hit) -- Events need a function (which will be run every time the event is fired)
    local cloned = game.Workspace.Part:clone() -- clone() is a method.
    cloned.Parent = game.Workspace -- Forgot this the first time. You need to give your new part a parent
    wait(10) -- Wait 10 seconds
    game.Workspace.Part:Destroy() -- Destroy is better than remove
end

game.Players.Player1.Torso.Touched:connect(onTouched) -- Connecting our function to the event. Note that this is for the player's torso, there is no Touched event for Humanoids.

Different events pass different arguments. A great way to figure out which arguments are passed is on the ROBLOX Wiki. The page for the touched event is right here.

Ad
Log in to vote
0
Answered by 10 years ago
game.Players.Player1.Character.Torso.Touched:connect(function(hit)
    local cloned = workspace.Part:clone()
    cloned.Parent = workspace
        game:GetService("Debris"):AddItem(cloned,10)
end)

Answer this question