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

Remove script on player touch parent part.?

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

✓ Accepted answer

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)

1 comment

0

Thank you.

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