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🥰
game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid").Touched:Connect(function(hit)
if hit.Name == "pa" then
workspace:FindFirstChild("ta"):Destroy()
end
end)
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
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
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
Well, you can’t expect me to spoon-feed you everything, just add a reference at the top to pa (goofy naming btw )
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)
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.
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)
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.
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.