I have these part then when it gets touched, it shows a GUI. Here’s the code:
local Part = script.Parent
local Namedplace = game.StarterGui.Winter
Part.Touched:Connect(function()
Namedplace.Enabled = false
Part.Touched not Part.Touched then
end)
2 Likes
may I ask what the issue is? i dont see anything wrong
Is this a server script? If it’s a server script then un enabling something in the StarterGui will not affect a player’s PlayerGui.
In line 5, Studio marks an error.
well .Touched is a script connection. The not thing is for boolens. thats why. if you want to make it go off and on when you go on the part do
local Part = script.Parent
local Namedplace = game.StarterGui.Winter
Part.Touched:Connect(function()
Namedplace.Enabled = not Namedplace.Enabled
end)
It’s a script in StarterGui, I think it needs to go in ServerScriptService.
Part.Touched is for parts, if it’s parented in the StarterGui it won’t even activate. It has to be parented into a part.
he can just do
local Part = workspace.PARTNAMEHERE
local Namedplace = game.StarterGui.Winter
Part.Touched:Connect(function()
Namedplace.Enabled = not Namedplace.Enabled
end)
I’ve actually made a mistake the script was located in the part that was being touched.
Put this as a server script parented into a part
local Part = script.Parent
Part.Touched:Connect(function(part)
local Namedplace = game.Players:GetPlayerFromCharacter(part.Parent).PlayerGui.Winter
Namedplace.Enabled = false
end)
Showing or hiding a Gui from starterGui does nothing. Also, you have not put an if
and an end
. This whole script doesn’t make any sense. You can’t do if Part.touched
or not part.touched. If you want to show a gui:
- Place a local script into your gui
- Use this script:
local Part = workspace.Part --Whatever your part is
Part.Touched:Connect(function()
script.Parent.Enabled = true --To show the gui, use true, not false
end)
1 Like
Got this error: Workspace.Part.Script:3: attempt to index nil with ‘PlayerGui’
I didn’t see the Gui, you didn’t put it in the script.
Oh right, I forgot something use this script instead. I’m assuming you put your gui named Winter in the startgui correct?
local Part = script.Parent
Part.Touched:Connect(function(part)
if game.Players:GetPlayerFromCharacter(part.Parent) == nil then return end
local Namedplace = game.Players:GetPlayerFromCharacter(part.Parent).PlayerGui.Winter
Namedplace.Enabled = not Namedplace.Enabled
end)
Yes, when I run the game should the GUI be enabled or disabled?
remove the then
Part.Touched not Part.Touched then
change this
Part.Touched not Part.Touched
Hey, I wanted to change how things were going. I have this code but I can’t find why the GUI isn’t showing.
local part = script.Parent
local Winter = game.StarterGui.Winter
local region = Region3.new(part.Position - part.Size/2, part.Position + part.Size/2)
while true do
local parts = workspace:FindPartsInRegion3(region, part)
for i, part in pairs(parts) do
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
Winter.Enabled = true
wait(1)
Winter.Enabled = false
end
end
wait(1)
end
region = region:ExpandToGrid(4)
Your problem is you are changing the gui in the startergui, this will not replicate to what the player is seeing. You need to get the gui from the player’s PlayerGui, put your code as this.
part = script.Parent
region = Region3.new(part.Position - part.Size/2, part.Position + part.Size/2)
while true do
local parts = workspace:FindPartsInRegion3(region, part)
for i, part in pairs(parts) do
if game.Players:GetPlayerFromCharacter(part.Parent) == nil then return end
player = game.Players:GetPlayerFromCharacter(part.Parent)
Winter = player.PlayerGui:FindFirstChild("Winter") -- gui from their playergui
if player ~= nil and Winter ~= nil then -- if they both exist
Winter.Enabled = true
wait(1)
Winter.Enabled = false
end
end
wait(1)
end
region = region:ExpandToGrid(4)
Ok, I’m confused if the Gui needs to be enabled or disabled when the game starts.
If the gui is disabled it will enable it then disable it after 1 second, it should work but I must ask why are you using region3? You can do it much simpler by making a touched script that opens a gui.