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

.Touched doesn't work, is it because of FilteringEnabled?

Works fine in studio, but fails in an actual server. No errors in output, and even debugging failed to show the problem, as "1" never prints, and it's literally the first line after the .touched function. I might be dumb, but I have absolutely no idea why this isn't working. FilteringEnabled is on if it matters, and this script is simply in a normal part inside of workspace.

local debounce = false

script.Parent.Touched:connect(function(player)
	print("1")
	if debounce == false then
		print("2")
		debounce = true
		game.ReplicatedStorage.events.sndGiggle:FireClient(player)
		game.Workspace.game.assets.location1:Destroy()
		game.ReplicatedStorage.assets.location2:Clone().Parent = game.Workspace.game.assets
		game.ReplicatedStorage.assets.location2a:Clone().Parent = game.Workspace.game.assets
		game.Workspace.events.metaldoor1:Destroy()
		game.Workspace.events.lights1:Destroy()
		game.Workspace.events.trigger.location1:Destroy()
	end
end)

Why, just why.

2 comments

0

Are you checking the Client or the Server Console?

0

Is it a LocalScript?

1 answer

✓ Accepted answer

Not 100% sure, don't take my word, but you might not be able to get player from onTouch directly. Instead try this...

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = workspace[hit.Parent.Name]
        local player = game.Players:GetPlayerFromCharacter(plr)
		--Stuff here
    end
end)

4 comments

0

That's true, the Touched event only returns the part that collided.

0

Ok, thank you. I'll try tomorrow and let you know if it worked

0

Worked like a charm. Thank you very much!

0

No problem! I am actually surprised it worked. One of the first questions I have ever answered :D

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