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

StarterGui won't enable after touching a part?

Asked by 7 years ago

Hi, I'm AswormeDorijan111 i need help. I'm good graphics developer but I don't know scripting a lot... So can you please help me how to StarterGui GUI Show when I touch a part. Please please help. :)

script.Parent.Touched:connect(function(hit)
game.StarterGui.Buy1.Enabled = true
wait(300)
game.StarterGui.Buy1.Enabled = false
end)

1 answer

Log in to vote
0
Answered by
CodeLad 31
7 years ago

Hello, your problem is that you're not detecting when a certain player is stepping over a part and you're accessing the StarterGui instead of the player's PlayerGui.

Here's the correct code. Put this in a script inside of your part.

local Players = game:GetService("Players")
local debounce = false --Prevent a ton of hit detections at once.

local function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then --Checks if a humanoid hit.
        if not debounce then
            debounce = true
            local chr = hit.Parent
            local plr = Players:GetPlayerFromCharacter(chr)
            if plr then --Checks if it was a player. 
                if plr.PlayerGui:FindFirstChild("Buy1") then --Makes sure the player has the right gui.
                    if plr.PlayerGui.Buy1.Enabled == false then
                        plr.PlayerGui.Buy1.Enabled = true
                        wait(3)
                        plr.PlayerGui.Buy1.Enabled = false
                    end
                end
            end
        end
        debounce = false
    end
end

script.Parent.Touched:connect(onTouched)

Hope this is what you wanted if it isn't tell me.

0
Man thanks you a lot you helped me a lot thanks you thanks you so muchhh :) AswormeDorijan111 531 — 7y
0
Make sure to accept my answer. : ) Happy to help. CodeLad 31 — 7y
Ad

Answer this question