This is for my game. I have all the code right with no errors.
script.Parent.MouseButton1Click:Connect(function()
game.StarterGui.ScreenGui.Enabled = true
script.Parent.Visible = false
end)
But when I start the game the code wont work properly, only the shop button disappears which is: "script.Parent.Visible = false" and the show me the shop: "game.StarterGui.ScreenGui.Enabled = true" is not working,and wont show up the shop, yes I have the ScreenGui disabled, and there are no output errors.
you need to make sure that you are useing the local StarterGui
when you do game.StarterGui.ScreenGui.Enabled = true you are changing the global instance and not the local. To fix this you need to use script.Parent and not game.StarterGui.
Below is some example code:
script.Parent.MouseButton1Click:Connect(function()
script.Parent.%how ever many parents it takes go get back to StarterGui%.ScreenGui.Enabled = true
script.Parent.Visible = false
end)
In the second line, You are enabling a GUI that's located in the StarterGui not the PlayerGui, To fix the problem, Change your code to this:
script.Parent.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = true
script.Parent.Visible = false
end)
Also, when posting code next time, use {} button instead
Related
I am starting to program in roblox, and I am making a Menu only for users who have a gamepass, I would like to know how I can make an exclusive graphical interface appear when a user has a gamepass, and the error here is that when a user buy that gamepass automatically the exclusive interface is activated to all the users of the server, I would like to know how to fix this problem.
The Script is on ServerScriptService
local MarketPlaceService = game:GetService("MarketplaceService")
local GamePass = 100725261
local Tool = game.StarterGui.ScreenGui.TPMenu
function compra(jugador)
local loTiene = false
local success, errorMensaje = pcall(function()
loTiene = MarketPlaceService:UserOwnsGamePassAsync(jugador.UserId, GamePass)
end)
if loTiene then
game.StarterGui.ScreenGui.TPMenu.Visible = true
end
end
game.Players.PlayerAdded:Connect(function(player)
compra(player)
end)
I tried to made this in a LocalScript and is not working
StarterGui is put into each Player's PlayerGui after they spawn, so editing it for one user would mean that other users would also see the changes after respawning. A better option would be to modify PlayerGui instead, like this:
function compra(jugador)
local loTiene = false
local success, errorMensaje = pcall(function()
loTiene = MarketPlaceService:UserOwnsGamePassAsync(jugador.UserId, GamePass)
end)
if loTiene then
jugador.CharacterAdded:Connect(function() -- Ran every time the player spawns
workspace:WaitForChild(jugador.Name) -- Wait for player to finish spawning
jugador.PlayerGui.ScreenGui.TPMenu.Visible = true
end)
end
end
Keep it as a Script in ServerScriptService.
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Frame.Visible == true then
script.Parent.Parent.Frame.Visible = false
end
if script.Parent.Parent.Frame.Visible == false then
script.Parent.Parent.Frame.Visible = true
end
end)
I am very new to coding (have started practically yesterday ) and ive decided to start with lua in roblox studio. The program here is working i can assure you (some things in code may not be in proper place since im having a bit trouble writing code on this site) but the code works. I have tried to make it seperatly for 2 buttons then I tried this and nothing seems to work. I am starting to think it is caused by the program itself and not the code since I can make other things invisible with that code. I've placed those 2 codes for visibility and invisibility in 1 thing since I've been told that events caused by the code happen at same time so some of them may not work.
Assume Visible is true. The first condition will be true and Visible will be set to false. Then, in the next condition Visible is false and the condition is therefore true, again. And it sets Visible back to true.
Now, in order to fix it you want to execute the second condition only if the first failed. Take a look at elseif https://www.lua.org/pil/4.3.1.html.
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Frame.Visible == true then
script.Parent.Parent.Frame.Visible = false
elseif script.Parent.Parent.Frame.Visible == false then
script.Parent.Parent.Frame.Visible = true
end
end)
This code is still quite bulky and can be improved:
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Frame.Visible = not script.Parent.Parent.Frame.Visible
end)
Now you assign true to Visible if Visible does not evaluate to true. It basically toggles the boolean.
I am having problems with the functionality of a script and I don't know how to solve it.
In the images below attach photos of the in-game problem, this means that the whole script works and in-game the property of the visible "bframe" is false but in-game this is not shown and I want to know how I can solve it ..
in-game mode the visibility of the "Bframe" it becomes false in the property (that's fine) but in-game this is not seen..
Does anyone know how to solve it?
Button script
-- Events
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Evento = ReplicatedStorage.RemoteEvent
-- end of Events
local button = script.Parent
local frame = script.Parent.Parent.Parent.Frame
Evento.OnClientEvent:Connect(function(argumento1)
button.MouseButton1Click:Connect(function()
if frame.Visible == false then
frame.Visible = true
button.Visible = false
else
frame.Visible = false
end
end)
end)
Server script
-- Events
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Evento = ReplicatedStorage.RemoteEvent
-- end of Events
game.Players.PlayerAdded:Connect(function(player)
Evento:FireClient(player,"argumento1")
print("testing probado")
end)
Redteam / touch part script called script
local wll = script.Parent.Part
local fr = game.StarterGui.TeamChangerGui.BFrame
local function Toch()
fr.Visible = false
fr.button.Visible = false
print("visible desactivado")
end
wll.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
Toch()
end
end)
**images**
enter image description here
enter image description here
enter image description here
Is the button script a localscript? if it is then it may be to do with the fireclient although I am not good at it and I usually use fireallclients passing through the player name then checking if its the correct name on the clients side script.
Otherwise I am not sure as it is an interesting issue i have never encountered. Hope it works!
can someone help me with that? I already got the code for resetting but when i open chat and say rrrrrrr, i keep dying.
here it is:
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local enabled = true
local userinputservice = game:GetService("UserInputService")
userinputservice.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.R and enabled then
character.Head:Remove()
enabled = false
wait(6)
enabled = true
end
end)
UserInputService#inputBegan gives you gameProcessedEvent as the second parameter of the function.
It indicates whether the game engine internally observed this input and acted on it. Generally, this refers to UI processing, so if a button was touched or clicked from this input, gameProcessedEvent would be true. This applies to TextBoxes, such as the chat.
All you need to check if if gameProcessedEvent is true.
local UserInputService = game:GetService("UserInputService");
local PlayersService = game:GetService("Players");
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return false end
if (input.KeyCode == Enum.KeyCode.R) then
PlayersService.LocalPlayer.Character.Head:Destroy()
end
end)
I'm a new developer to roblox and figured it would be a good place to start learning to make games. I was working on my game today and I ran into an issue. I wanted to press 'E' while by a NPC and I got that to work. The only problem was, I have no clue how to make the GUI appear and Dissapear when I press E. This is what I have written,
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local Npc = game.Workspace.Noob.Head
UIS.InputBegan:connect(function(keyCode)
if keyCode.keyCode == Enum.KeyCode.E then
if (Npc.Position - HumanoidRootPart.Position).magnitude < 15 then
game.StarterGui.TextF.TextLabel.Visible = 0
wait(3)
game.StarterGui.TextF.TextLabel.Visible = 1
end
end
end)
it comes out with no error. The code to press E still works, but the GUI does not pop up. I have tried setting the values to True or False
I've Figured it out. if anyone is looking at this question and wondering, this script is almost ok. The only problem is that you cannot change a GUI from the starter GUI, you have to call it from LocalPlayerGui Like this:
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local Npc = game.Workspace.Noob.Head
UIS.InputBegan:connect(function(keyCode)
if keyCode.keyCode == Enum.KeyCode.E then
if (Npc.Position - HumanoidRootPart.Position).magnitude < 15 then
print("Key E was pressed")
game.Players.LocalPlayer.PlayerGui.TextF.TextLabel.Visible = true
wait(3)
game.Players.LocalPlayer.PlayerGui.TextF.TextLabel.Visible = false
end
end
end)