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

Why my script to appear GUI when you click block doesn't works?

Asked by 4 years ago

Hello! I'm trying to make GUI appear when I touch block. I did this script below but it doesn't works, also I don't have any errors, any ideas what should I change? (script is in local script)

local Player = game.Players.LocalPlayer

local function change(hit)
    if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then

        Player.PlayerGui.UniformGui.Frame.Visible=true

    end
end


script.Parent.Touched:Connect(change)
0
Line 4 may be the problem, try putting ~= nil as a condition for the two conditions... Also put a print before the if statement and one inside it to see what your script is doing when you touch the block (i.e. is it even detecting if you touch it? Is it working correctly but line 6 is the issue? Etc.) AlexTheCreator 461 — 4y
0
are you using a local script? WideSteal321 773 — 4y
0
I tried this script with print and it works correct, just something is wrong in line 6 ThadonROOX 47 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

The problem is that you're using a local script, local scripts don't work in the workspace. I'd suggest using a normal script and putting your GUI inside of the script, and when you touch the brick simply clone the GUI into the player's PlayerGui folder by doing something like this:

local gui = script.gui -- change this to wherever your GUI is
script.Parent.Touched:Connect(function (hit)
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
gui:Clone() -- Clones the GUI
local playerName = hit.Parent.Name
local player = game.Players[playerName]
gui.Parent = player.PlayerGui -- Puts the GUI in the player's PlayerGui Folder
end
end)

I'm not an expert in scripting, and if anyone has a better solution or sees any errors in my answer, feel free to comment! ;)

0
Not working mate ThadonROOX 47 — 4y
0
nvm, it works ThadonROOX 47 — 4y
0
Thank you ThadonROOX 47 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

It seems you have your local script inside workspace. The reason why it doesn't work is because local scripts don't work inside workspace. Local scripts will only run if they are a descendant of either a Player's Backpack, Character model, PlayerGui, PlayerScripts or the ReplicatedFirst service.

To fix this you would simply just need to parent the local script somewhere that was stated above.

0
Should I use remote events then? ThadonROOX 47 — 4y
0
No need to use RemoteEvents. Just parent your local script to somewhere I mentioned in my answer. Try putting the local script inside StarterGui and just change ``script.Parent.Touched`` to ``workspace.Part.Touched``. Just change 'Part' to the name of the part you want to touch to fire this event. xInfinityBear 1777 — 4y
0
Still not working ThadonROOX 47 — 4y

Answer this question