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

GUI only popping up when the part is touched?

Asked by 4 years ago
Edited 4 years ago

I only want my gui to show when the part is being touched, right now it is staying on the screen until you X out of it. This is what I have using a remote event(probably wrong thing to use)

local limit = 2

script.Parent.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then

            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if player.leaderstats.Points.Value >= limit then

                if hit.Parent:FindFirstChild("Torso") then
                    script.Parent.CanCollide = false
                elseif hit.Parent:FindFirstChild("UpperTorso") then
                    script.Parent.CanCollide = false

            end
        end
    end
end)
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid")then
        game.ReplicatedStorage.Popup:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
    end
end)
0
u s e c o d e b l o c k s f o r y o u r e n t i r e s c r i p t User#32819 0 — 4y
0
ok i dont get it when do you want it to pop up? because its like its not popping up at all? what's your problem xd User#32819 0 — 4y
0
it pops up when a part is touched but I only want it to show when the part is being touched, right now it stays after you stop touching the part Imgood543 21 — 4y
0
Why are you even using :FireClient()? The player GUI can be accessible by doing game.Players:GetPlayerFromCharacter(hit.Parent). Bruh BradNewTypical 232 — 4y
View all comments (2 more)
0
im new to scripting Imgood543 21 — 4y
0
if you want it to pop up when touched, do script.Parent.Touched, and when you want it to go away, use script.Parent.TouchEnded. killerbrenden 1537 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Your solution to this is TouchEnded. CanCollide has nothing to do with stopping a touched event, so don't use that. This is what you should be using

Part.Touched:Connect(function(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) then
        -- Fire a client event to pop up a GUI
    end
end)

Part.TouchEnded:Connect(function(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) then
        --Close the GUI with a client event
    end
end)

A better solution would be to use magnitude from a local script. It will work nicely if it's a cylinder too. That would work like this

local RunService = game:GetService('RunService')

local Range = 10 --Distance in studs
local Part = game.Workspace.Part --Part that you want to detect when touched
local LocalPlayer = game.Players.LocalPlayer

repeat wait() until LocalPlayer.Character

local PlayerCharacter = LocalPlayer.Character
local HumanoidRootPart = PlayerCharacter:WaitForChild('HumanoidRootPart')

RunService.Heartbeat:Connect(function() --fires every frame/FPS
    if (HumanoidRootPart.Position - Part.Position).magnitude < Range then
        --Pull up the GUI from here

    else
        --Close the GUI here
    end
end)

Hope this helps out.

0
Where do I put the local script? StarterCharacterScripts? Imgood543 21 — 4y
0
also does this work on a normal part because I can't make it work Imgood543 21 — 4y
Ad

Answer this question