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

How To Make My Touched Script Filtering Enabled?

Hello... I am getting the hang of using filtering enabling to ensure user safety but I only know how to use it on Screen Gui related stuff. How can I make this Touched and TouchEnded function work with filtering enabled?

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

script.Parent.TouchEnded:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = workspace[hit.Parent.Name]
        local player = game.Players:GetPlayerFromCharacter(plr)
		player.PlayerGui.GeneralStoreMusic.Playing = false
	end
end)

3 answers

✓ Accepted answer

Listen for the BasePart.Touched event client-side, and modify the GUI client-side. There's no point doing this server-side at all, you are merely wasting bandwith and adding latency this way.

Alternatively, listen for Humanoid.Touched client-side! Also worth pointing out that BasePart.TouchEnded will fire a ton when an object like a character is walking into it, so I recommend using a loop in the touched listener that checks for the distance away from the object before making the GUI disappear, and adding a debounce on making the GUI appear.

Fire a Remote Event to the client.

1 comment

0

This is a waste. Why do this server-side at all?

In a LocalScript inside StarterGui:

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local part = -- Reference your part here

part.Touched:Connect(function(hit)
    if hit.Parent == player.Character  then
        player.PlayerGui.GeneralStoreMusic:Play()
    end
end)

part.TouchEnded:Connect(function(hit)
    if hit.Parent == player.Character then
        player.PlayerGui.GeneralStoreMusic.Playing = false
    end
end)

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