Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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.

0
Are you checking the Client or the Server Console? yyyyyy09 246 — 5y
0
Is it a LocalScript? PreciseLogic 271 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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)
0
That's true, the Touched event only returns the part that collided. jackfrost178 242 — 5y
0
Ok, thank you. I'll try tomorrow and let you know if it worked ZeMeNbUiLdEr 104 — 5y
0
Worked like a charm. Thank you very much! ZeMeNbUiLdEr 104 — 5y
0
No problem! I am actually surprised it worked. One of the first questions I have ever answered :D BunnyFilms1 297 — 5y
Ad

Answer this question