Scripting Support for my game

I made that script for:
There is two thing in Workspace, ta and pa.
My goal: When player touched pa, ta will get destroyed.

Script:

local player = game.Players.LocalPlayer
local ta = workspace.ta 

local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if humanoid and otherPart.Name == "pa" then 
		ta:Destroy() 
	end
end

ta.Touched:Connect(onTouch) 

Can you tell me what is wrong here?
– Edit: Thank you all for helping I finished my horror game! Love you all🥰

5 Likes
game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid").Touched:Connect(function(hit)
if hit.Name == "pa" then
workspace:FindFirstChild("ta"):Destroy()
end
end)
2 Likes
local player = game.Players.LocalPlayer
local ta = workspace.ta 
local conn;

local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if humanoid then
        conn:Disconnect()
		ta:Destroy() 
	end
end

conn = pa.Touched:Connect(onTouch)

The logic was all wrong, nothing to be explained more

5 Likes
local player = game.Players.LocalPlayer
local ta = workspace.ta 

local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if humanoid then 
		ta:Destroy() 
	end
end

ta.Touched:Connect(onTouch)

this should work, btw this is my first time answering, so if it doesnt work, tell me :wink:

2 Likes
local player = game.Players.LocalPlayer
local ta = workspace.ta 
local pa = workspace.pa

local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if humanoid then 
		ta:Destroy() 
	end
end

pa.Touched:Connect(onTouch) 

if this is your entire script then i think the other replies forgot to define pa

3 Likes


ta still exist but thank you :smiley:

2 Likes

I want ta get destroyed when player touched pa but thank you :smiley:

2 Likes


still exist

1 Like

if it worked mark my reply as the solution

2 Likes


:pensive:

1 Like

Sorry it didn’t but thank you so much

2 Likes

Well, you can’t expect me to spoon-feed you everything, just add a reference at the top to pa (goofy naming btw :joy:)

local player = game.Players.LocalPlayer
local ta = workspace.ta
local pa = workspace.pa --Change to path to pa in workspace if not this
local conn;

local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if humanoid then
        conn:Disconnect()
		ta:Destroy() 
	end
end

conn = pa.Touched:Connect(onTouch)
1 Like

Your behavior is kinda heart-breaking. I changed them to make it short the orginal names: pa= part and ta= talisman.
There is 35+ scripts in my game and it is the reason. I work 6 hours for scripting. I’m also working on C++ and phyton so it is normal to I’m having troubles. Thanks for your beautiful work.

1 Like

His behaviour is absolutely not unreasonable. All you had to do was add 1 line of code, which was literally only the reference to “pa”. It’s an insult to us for you to play the hurt victim, when you demand that we spoonfeed you.
P.S., @Mystxry12 , there’s a built in-function that immediately disconnects the function once run initially, called :Once.

local player = game:GetService("Players").LocalPlayer
local ta = workspace.ta
local pa = workspace.pa --Change this variable to the pa's location

pa.Touched:Once(function(otherPart)
    local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
		ta:Destroy() 
	end
end)
3 Likes

damn nice call, I had known abt :Once but it never crossed my mind that I cud use it in this scenario, thanks for the tip

2 Likes

My man spitting facts, respect

2 Likes

Yeah, people who play the victim are pretty pathetic when we (mostly you guys) are helping them.

2 Likes

I may be wrong, but in the images OP sent you can see pa and ta as models. Again, not sure if these are other things but I just thought I should point it out.

1 Like

Yeah I know but I tried as parts or meshes I’ll check it<3

Helping is not making fun of who needs help. Remember, I ask “Can you tell me what is wrong here” I didn’t want you to write a script. Please watch your behavior I’m not your enemy or I didn’t even tell you a bad word, thanks for all.

1 Like