Please help me with this problem.
I am trying to change the photos in the surfaceGUI, It’s suppose to change on every click.
I don’t know why it won’t work I get no errors in the output
I tried to use different functions for each photo, didn’t work and I got no errors.
I also tried to just move them from ‘Screen’ to ‘SurfaceGUI’ then from ‘SurfaceGUI’ to ‘Screen’ without deleting them
Here’s the script
local photo1 = workspace.Room.Main.Screen:WaitForChild("Example1")
local photo2 = workspace.Room.Main.Screen:WaitForChild("Example2")
local photo3 = workspace.Room.Main.Screen:WaitForChild("Example3")
script.Parent.Activated:Connect(function(click)
--1
if click then
photo1.Parent = workspace.Room.Main.Screen.SurfaceGui
--2
if click then
photo1:Destroy()
photo2.Parent = workspace.Room.Main.Screen.SurfaceGui
--3
if click then
photo2:Destroy()
photo3.Parent = workspace.Room.Main.Screen.SurfaceGui
end
end
end
end)
Wut exactly are you even doing with this? You’re literally encasing all of conditional checks inside each other, couldn’t it just be more simpler to do this?
local photo1 = workspace.Room.Main.Screen:WaitForChild("Example1")
local photo2 = workspace.Room.Main.Screen:WaitForChild("Example2")
local photo3 = workspace.Room.Main.Screen:WaitForChild("Example3")
script.Parent.Activated:Connect(function(click)
--1
print("Fired")
if click then
print("Wut")
photo1.Parent = workspace.Room.Main.Screen.SurfaceGui
photo1:Destroy()
photo2.Parent = workspace.Room.Main.Screen.SurfaceGui
photo2:Destroy()
photo3.Parent = workspace.Room.Main.Screen.SurfaceGui
end
end)
Also all of these photos will instantly fire the moment the event detects the GUIButton gets activated, is that what you want…?
First off, why are you using conditionals inside each other when they all check for the same thing? Second, if you’re trying to make the photos change for each click, you can try this:
local mainsgui = workspace.Room.Main.Screen.SurfaceGui
local photo1 = workspace.Room.Main.Screen:WaitForChild("Example1")
local photo2 = workspace.Room.Main.Screen:WaitForChild("Example2")
local photo3 = workspace.Room.Main.Screen:WaitForChild("Example3")
local photonum = 1
script.Parent.Activated:Connect(function(click)
if photonum < 4 then
if photonum == 1 then
photo1.Parent = mainsgui
photonum += 1
else if photonum == 2 then
photo1:Destroy()
photo2.Parent = mainsgui
photonum += 1
else if photonum == 3 then
photo2:Destroy()
photo3.Parent = mainsgui
photonum += 1
end
end)
I assumed what you were trying to do though, and you can also optimize this a lot more than how I left it. Unless you tell us exactly what you’re trying to achieve, this is as far as help could go.
It’s suppose to change the photos into the SurfaceGUI on every click.
So that they change separately and not at the same time.
And this script is in a tool not a GUIButton
I think the script didn’t work, I changed it a bit to test it.
local mainsgui = workspace.Room.Main.Screen.SurfaceGui
local photo1 = workspace.Room.Main.Screen:WaitForChild("Example1")
local photo2 = workspace.Room.Main.Screen:WaitForChild("Example2")
local photo3 = workspace.Room.Main.Screen:WaitForChild("Example3")
local photonum = 1
script.Parent.Activated:Connect(function(click)
if photonum < 4 then
if photonum == 1 then
photo1.Parent = mainsgui
print("Worked 1")
photonum += 1
else if photonum == 2 then
photo1:Destroy()
photo2.Parent = mainsgui
print("Worked 2")
photonum += 1
else if photonum == 3 then
photo2:Destroy()
photo3.Parent = mainsgui
print("Worked 3")
photonum += 1
end
end
end
end
end)
it didn’t printed (Worked 1,2 and 3) on each click.
And there was no errors too.
(Sorry for the late reply)
Where’s your script located? Is it a Server script or a Local script? LocalScripts that are descendants of the workspace (parented to something which is in the workspace, for example) won’t run. That means that any events you put inside of it will not fire, i.e. Button.Activated will not detect clicks. Also, since you’re referencing the workspace, I don’t think it’s a ScreenGui, more like a SurfaceGui (the one that is displayed on top of a part). The following will work with the assumption that it’s the latter. If not, feel free to correct me and I’ll se what I can do.
If it’s a local script, move the entire SurfaceGui to StarterGui and use the Adornee property to choose which part (in the workspace) it should be displayed on. Unless you were using variables that are relative to the script’s position, like script.Parent and you know that will not work once you change the parent, you can keep your current code. From what I’ve seen, you should be fine.
Lastly, a tip which may or may not work depending on your use-case, other scripts, and Gui strucutre, is to change the Photo’s AssetId (or Image) property instead of deleting/re-parenting your pictures.
It’s located in a tool in the starterPack which means it will be in the player’s Backpack when they start the game, and it’s a Script not a LocalScript.
Sorry guess that was my bad, I meant SurfaceGui not ScreenGui
Guess I already tried that, it didn’t work although
Thanks for replying on the topic, I appreciate every reply that is trying to help me!
Does your tool have a Handle part and has HandleRequired set to true? The tool.Activated event won’t fire if there’s no handle inside of it.
Check if the rest of the script runs by placing print() outside of the function. If it prints, we know that it’s a problem with the function and it isn’t firing. It might also be a good idea to print something before any conditionals are used, just in case (but judging from your code, it shouldn’t be a problem).
The tool has HandleRequired set to true and it has a Handle.
I dont’ think the script even runs, I put a Print("Started") at the start of the script and I put a Print("End") at the end of the script.
But it didn’t print Started or End.
print("Script online")
local mainsgui = workspace.Room.Main.Screen.SurfaceGui
local photo1 = workspace.Room.Main.Screen:WaitForChild("Example1")
local photo2 = workspace.Room.Main.Screen:WaitForChild("Example2")
local photo3 = workspace.Room.Main.Screen:WaitForChild("Example3")
local photonum = 1
script.Parent.Activated:Connect(function()
print("Activated")
if photonum < 4 then
if photonum == 1 then
photo1.Parent = mainsgui
print("Worked 1")
photonum += 1
elseif photonum == 2 then
photo1:Destroy()
photo2.Parent = mainsgui
print("Worked 2")
photonum += 1
elseif photonum == 3 then
photo2:Destroy()
photo3.Parent = mainsgui
print("Worked 3")
photonum += 1
end
end
end)
The only instance that I could see if the first print() doesn’t work, is that if the Tool is parented somewhere else which wouldn’t make sense? Since you stated earlier:
Yea, that’s true.
But I started using this script since it’s better.
local mainsgui = workspace.Room.Main.Screen.SurfaceGui
local photo1 = workspace.Room.Main.Screen:WaitForChild("Example1")
local photo2 = workspace.Room.Main.Screen:WaitForChild("Example2")
local photo3 = workspace.Room.Main.Screen:WaitForChild("Example3")
local photonum = 1
script.Parent.Activated:Connect(function(click)
if photonum < 4 then
if photonum == 1 then
photo1.Parent = mainsgui
print("Worked 1")
photonum += 1
else if photonum == 2 then
photo1:Destroy()
photo2.Parent = mainsgui
print("Worked 2")
photonum += 1
else if photonum == 3 then
photo2:Destroy()
photo3.Parent = mainsgui
print("Worked 3")
photonum += 1
end
end
end
end
end)
And I relized that it doesn’t even run the script for some reason.