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

Remove script on player touch parent part.?

Asked by
DBoi941 57
5 years ago

Trying to get the part to spin all the time till a player touched the part than remove the script. I am very new to this. This is what I have and it does not work.

local player = game.Players.LocalPlayer
local part = script.Parent
    if part.Name == "Main" then
        script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(.01,0,0)
        wait()
        else
    if player:Touched(part) then
        script:Destroy()
    end
end 
player.Character.Humanoid.Touched:connect (part)

1 answer

Log in to vote
1
Answered by 5 years ago

This is because :connect is deprecated, use :Connect.

You tried to pass an object to the :Connect method, which it must be a function.

Also make sure its a Local script to use LocalPlayer.

local plr = game:GetService('Players').LocalPlayer

function onTouch(part, humanoidPart)
    if part.Name == 'Main' then
        part.CFrame = part.CFrame * CFrame.fromEulerAnglesXYZ(.01, 0,0)
    elseif part.Parent == plr.Character then -- if the part parent is of the character 
        script:Destroy()
    end
end

plr.Character.Humanoid.Touched:Connect(onTouch)
0
Thank you. DBoi941 57 — 5y
Ad

Answer this question