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

Help telling a local script that a block was touched?

Asked by
yelsew 205 Moderation Voter
9 years ago

I cannot figure out how to tell a local script that a certain block was touched, and trigger an event to open up a gui. No need for a huge block of code, just give me a short run down of how I should do it. Thanks in advance!

1 answer

Log in to vote
1
Answered by
4Bros 550 Moderation Voter
9 years ago

Well, i'm not sure what you mean by this, do you mean telling the localscript what block the character touched, or having a preset block with a touch event telling the localscript it was touched?

-- Localscript
repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local character = player.Character
local block  = game:GetService'Workspace':WaitForChild("Part")
local gui = script.Parent  -- Put localscript inside gui
gui.Visible = false
local debounce = false

block.Touched:connect(function(p)
    if debounce then return end
    debounce = true
    local humanoid = p.Parent:FindFirstChild'Humanoid'
    if humanoid and p.Parent == character then
        gui.Visible = true
    end
    debounce = false
end)



1
I mean a preset block with a touch event. Sorry. And this is a singleplayer game as well. If that helps yelsew 205 — 9y
0
Well if that's what you mean, then the above script should work perfectly, just parent it inside the gui 4Bros 550 — 9y
1
K thanks! yelsew 205 — 9y
Ad

Answer this question