So I was looking through the forum and articles. I put this script inside my game just to use it as a note. But, it unanchores everything but the spawn. I tried placing different game scripts into Studios to see but those did not cause a crash so it just seems to be the script. Any thoughts?
*Btw the script is an event and when I play Studios it runs the event print without the character touching it and everything unanchores besides the spawn part.
*Reference page: Using Parameters and Events | Roblox Creator Documentation
local trap = script.Parent
local function onTouch(objectTouched)
print("Something touched the trap")
-- Destroy the touching object
objectTouched:Destroy()
end
trap.Touched:Connect(onTouch)
Well I was just using it as example, but essentially it was just for a humanoid. But I guess I could just change it to detect anything besides Baseplate or just detect a humanoid.
If you are trying to detect Humanoids, it won’t work. To my knowledge they only detect parts (someone go fact check me lol). If you want to detect characters, the part will detect part in the character (e.g. Head, UpperTorso etc.) which can then give you the character (using objectTouched.Parent).
local part = script.Parent
local function onPartTouched(otherPart)
local partParent = otherPart.Parent
-- Look for a humanoid in the parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
-- Do something to the humanoid, like set its health to 0
humanoid.Health = 0
end
end
part.Touched:Connect(onPartTouched)
local part = script.Parent
local function onPartTouched(otherPart)
local partParent = otherPart.Parent
-- Look for a humanoid in the parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
otherPart:Destroy() --Destroy Touching Part
end
end
part.Touched:Connect(onPartTouched)
True yes, sorry I changed my script to destroy the humanoid as a global variable instead of being inside as a conditional, thats why I was confused a bit but thanks for the help there lol. Have a blessed day