I’ve been directed here after my previous post here: Surface Text Button not working - #10 by ScriptedEthqn due to the fact e could not find a solution and now believe it to be the script.
I don’t know what to do, ive tried changing it to a click detector and there was no change. The surface gui IS in playerGui.
Could my issue be related to the fact I have changed the camera?
Here is the script in whole:
local Players = game:GetService("Players")
local X = game:GetService("StarterGui")
local GUI = game:GetService("GuiService")
local currentCamera = workspace.CurrentCamera
local menuCam = workspace.MainMenu.CameraPart
local CamStep = true
currentCamera.CameraType = Enum.CameraType.Scriptable
game:GetService("RunService").RenderStepped:Connect(function(deltatime)
if CamStep == true then
currentCamera.CFrame = menuCam.CFrame
else return end
end)
local playButton = Players.LocalPlayer.PlayerGui.SurfaceGui.Frame.TextButton
local playDetector = workspace.MainMenu.Play.PlayDETECT --TEMPORARY FIX
local spawnSelection = "default"
local SpawnLocations = {
["sector3"] = workspace.SpawnA.CFrame,
["default"] = workspace.SpawnB.CFrame,
["administration"] = workspace.SpawnC.CFrame
}
local Character = Players.LocalPlayer.Character
local HumRoot = Character:WaitForChild("HumanoidRootPart")
function playEntered()
print("Play pressed")
CamStep = false
currentCamera.CameraType = Enum.CameraType.Scriptable.Value(false)
Character:SetPrimaryPartCFrame(SpawnLocations[spawnSelection])
end
playButton.Activated:Connect(playEntered)
It is local.
1 Like
Katrist
(Katrist)
February 5, 2023, 6:09pm
#2
You might need to use .MouseButton1Down, also make sure that playButton is actually a GuiButton and not a frame.
Fixed code:
--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
local HumRoot = Character:WaitForChild("HumanoidRootPart")
local playButton = LocalPlayer.PlayerGui.SurfaceGui.Frame.TextButton
local playDetector = workspace.MainMenu.Play.PlayDETECT --TEMPORARY FIX
local currentCamera = workspace.CurrentCamera
local menuCam = workspace.MainMenu.CameraPart
--//Controls
local CamStep = true
local spawnSelection = "default"
--//Tables
local SpawnLocations = {
sector3 = workspace.SpawnA.CFrame,
default = workspace.SpawnB.CFrame,
administration = workspace.SpawnC.CFrame
}
--//Functions
currentCamera.CameraType = Enum.CameraType.Scriptable
RunService.RenderStepped:Connect(function(deltatime)
if CamStep then
currentCamera.CFrame = menuCam.CFrame
end
end)
playButton.MouseButton1Down:Connect(function()
print("Play pressed")
CamStep = false
currentCamera.CameraType = Enum.CameraType.Scriptable.Value
Character:PivotTo(SpawnLocations[spawnSelection])
end)
Using that the camera no longer moves though; therefore I cannot test if the button fix works?
Katrist
(Katrist)
February 5, 2023, 6:16pm
#4
Any errors? The camera should still work, as I’ve just rearranged your script.
No errors other than the one I’ve been expecting
18:13:59.093 Players.ScriptedEthqn.PlayerScripts.MainMenuLocalScript:8: attempt to index nil with 'WaitForChild' - Client - MainMenuLocalScript:8
18:13:59.093 Stack Begin - Studio
18:13:59.093 Script 'Players.ScriptedEthqn.PlayerScripts.MainMenuLocalScript', Line 8 - Studio - MainMenuLocalScript:8
18:13:59.093 Stack End - Studio
18:13:59.355 Loaded - Client - CharSystem:8
18:13:59.355 Activated - Client - CharSystem:19
18:13:59.358 Cloned - Client - CharSystem:22
18:14:02.002 Applied - Client - CharSystem:26
18:14:02.002 Enum.AnimationPriority.Action - Client - CharSystem:29
18:14:04.523 Disconnect from ::ffff:127.0.0.1|57212 - Studio```
Katrist
(Katrist)
February 5, 2023, 6:18pm
#6
Oh I didn’t know that was the error in the first place lol.
Fixed code:
--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumRoot = Character:WaitForChild("HumanoidRootPart")
local playButton = LocalPlayer:WaitForChild("PlayerGui").SurfaceGui.Frame.TextButton
local playDetector = workspace.MainMenu.Play.PlayDETECT --TEMPORARY FIX
local currentCamera = workspace.CurrentCamera
local menuCam = workspace.MainMenu.CameraPart
--//Controls
local CamStep = true
local spawnSelection = "default"
--//Tables
local SpawnLocations = {
sector3 = workspace.SpawnA.CFrame,
default = workspace.SpawnB.CFrame,
administration = workspace.SpawnC.CFrame
}
--//Functions
currentCamera.CameraType = Enum.CameraType.Scriptable
RunService.RenderStepped:Connect(function(deltatime)
if CamStep then
currentCamera.CFrame = menuCam.CFrame
end
end)
playButton.MouseButton1Down:Connect(function()
print("Play pressed")
CamStep = false
currentCamera.CameraType = Enum.CameraType.Scriptable
Character:PivotTo(SpawnLocations[spawnSelection])
end)
still not spawning with the camera moved, got this :44.261 SurfaceGui is not a valid member of PlayerGui "Players.ScriptedEthqn.PlayerGui" - Client -
but I fixed that had it named differently
My surface gui is named PlayGUI local playButton = LocalPlayer:WaitForChild("PlayerGui").PlayGUI.Frame.TextButton
Katrist
(Katrist)
February 5, 2023, 6:32pm
#8
You need to use another :WaitForChild then.
Try this:
--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumRoot = Character:WaitForChild("HumanoidRootPart")
local playButton = LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("PlayGUI").Frame.TextButton
local playDetector = workspace.MainMenu.Play.PlayDETECT --TEMPORARY FIX
local currentCamera = workspace.CurrentCamera
local menuCam = workspace.MainMenu.CameraPart
--//Controls
local CamStep = true
local spawnSelection = "default"
--//Tables
local SpawnLocations = {
sector3 = workspace.SpawnA.CFrame,
default = workspace.SpawnB.CFrame,
administration = workspace.SpawnC.CFrame
}
--//Functions
currentCamera.CameraType = Enum.CameraType.Scriptable
RunService.RenderStepped:Connect(function(deltatime)
if CamStep then
currentCamera.CFrame = menuCam.CFrame
end
end)
playButton.MouseButton1Down:Connect(function()
print("Play pressed")
CamStep = false
currentCamera.CameraType = Enum.CameraType.Scriptable
Character:PivotTo(SpawnLocations[spawnSelection])
end)
currentCamera.CameraType = Enum.CameraType.Scriptable
RunService.RenderStepped:Connect(function(deltatime)
if CamStep then
currentCamera.CFrame = menuCam.CFrame
end
end)
appears to have stopped working
i dont think surfaceGui is working on the playerGui.
Why would it not be? I thought I checked that but I can check it again.
because surfaceGui is literally surface gui
No, you put it in player gui and connect it to the part