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

How To Make My Touched Script Filtering Enabled?

Asked by 6 years ago

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

Log in to vote
1
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

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.

Ad
Log in to vote
0
Answered by 6 years ago

Fire a Remote Event to the client.

0
This is a waste. Why do this server-side at all? Avigant 2374 — 6y
Log in to vote
0
Answered by 6 years ago

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)

Answer this question