You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want a String Value called " texty " to change.
-
What is the issue? Include screenshots / videos if possible!
The value isn’t changing what ever I try to do to it.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried:
- changing it on a local script
- activating a remoteEvent from local to server
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Relevant Code
Attempt1 (activating a remoteEvent from local to server)
Server Script (game.ServerScriptService.MainScript)
game.ReplicatedStorage.Events.MoveForwardEvent.OnServerEvent:Connect(function(plr, stageValue, amount)
--
plr.PlayerGui:FindFirstChild("ScreenGui").TextLabel.Text = tonumber(plr.PlayerGui:FindFirstChild("ScreenGui").TextLabel.texty.Value) - 10
print("it works")
local oldPos = game.Workspace:FindFirstChild(plr.Name).HumanoidRootPart.Position
end)
Local Script (game.StarterGui.ScreenGui.TextLabel.ButtonMainScript2)
script.Parent.Parent.Backwards10Button.MouseButton1Click:Connect(function()
print("it works! (client-side)")
game.ReplicatedStorage.Events.MoveForwardEvent:FireServer(game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value, 10)
end)
Local Script (game.StarterGui.ScreenGui.TextLabel.Backwards10ButtonScript) This script is for checking if the value has been changed.
local value = game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value
local debounce = false
while wait(0.1) do
if debounce == false then
script.Parent.Text = game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value
script.Parent.texty.Value = script.Parent.Text
debounce = true
end
if game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value <= 10 then -- if there 9 or less stages / Backwards10Button
script.Parent.Parent.Backwards10Button.Visible = false
elseif game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value > 10 then
script.Parent.Parent.Backwards10Button.Visible = true
end
if game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value <= 1 then
script.Parent.Parent.BackwardsButton.Visible = false
elseif game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value > 1 then
script.Parent.Parent.BackwardsButton.Visible = true
-- V for checking if the value was changed. V
print(game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value)
end
----------------------------------------------------------------------------------------------------------------------------------------
end
2 Likes
Forgot to mention that the value, texty, is very important and it is used to tell the player what stage he/she is on (I’m doing a diff. chart)
The issue is that you’re trying to access playergui from the server you need to fire to the client. You can’t access local player GUIs through a server script
For organizational purposes I’m going to define the event.
SERVER SCRIPT
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MoveForward = ReplicatedStorage.MoveForwardEvent
-- code here for positions and stuff, make sure you do MoveForward:FireClient() or FireAllClients() if you want it for all players
CLIENT / LOCAL SCRIPT
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MoveForward = ReplicatedStorage.MoveForwardEvent
local Players = game:GetService("Players")
local localPlayers = Players.LocalPlayer
MoveForward.OnClientEvent:Connect(function()
--code here for the local player gui etc
end)
So wait, where do I get the (screenGUI.TextLabel.Backwards10Button) from? StarterGui or the GUI cloned into (game.playerName.playerGUI)?
The PlayerGui always, no matter what you do
Sorry if i bother you with more questions.
- How do I get the player’s name who clicks on the moveForward button?
- What relation chain should I be doing so i can get the player’s GUI and then detect when he/she clicks on it?
*Doesn’t MouseButton1Click return no arguments?
Basically, all i need is (relation chain leading the screenGUI).TextButton.MouseButton1Click:Connect()
On the client you could return the players name, use the local script for when they click on it and then enable it by doing local GUI = Players.LocalPlayer:WaitForChild(“PlayerGui”).Name
GUI.Enabled = true etc
Ok, so i got to the part where the button is activated and it works, sort of. It makes the GUI text change, however, a script used to tell me what the actual value of “texty” is and it is the same before i hit the button. If my code works the script will tell me that “texty” has changed.
(edit) it works, i forgot to change the script used to determine the value of “texty”
Please show me this part to better help you
Edit:
Oh okay
I hope I was able to help, if I did be sure to give the post the solution marker to let others know this was solved and if they encounter the same issue they can see what I sent you.
Ok one last thing before we are done, when the player clicks on a move forward button he/she will be teleported to the appropriate checkpoint. The code will select said checkpoint from a folder called checkpoints which has all of the checkpoint parts. Should I use a remoteEvent or stay within the local script
That’s up to you but you can change their humanoidrootpart.CFrame to he Endpoint.CFrame on the local script
Ok so i went with the remoteEvent and it printed, showing that it ran, but it didn’t teleport the player like it was to posed to.
Local Script
game.Players.LocalPlayer.PlayerGui:FindFirstChild('ScreenGui').Backwards10Button.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.PlayerGui:FindFirstChild('ScreenGui').TextLabel.texty.Value -= 10
game.ReplicatedStorage.Events.MoveForwardEvent:FireServer(tonumber(game.Players.LocalPlayer.PlayerGui:FindFirstChild('ScreenGui').TextLabel.texty.Value), -10)
end)
Server Script
game.ReplicatedStorage.Events.MoveForwardEvent.OnServerEvent:Connect(function(plr, current, amount)
--
-- Get the Player's humanoidRootPart Position
local oldPos = game.Workspace:FindFirstChild(plr.Name).HumanoidRootPart.Position
-- Get the new checkpoint's position
local newPos = game.Workspace.Checkpoints:FindFirstChild("Checkpoint" .. tostring(current - amount))
oldPos = newPos
print("it works!")
end)
You need to move the position on the local script and when you do it do newpos.CFrame and HumanoidRootPart.CFrame for the oldPos
In attempt #2, I used a local script and it gives me an error when I try to go past 11, oh and by the way it doesn’t do any teleporting
game.Players.LocalPlayer.PlayerGui:FindFirstChild('ScreenGui').Backwards10Button.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.PlayerGui:FindFirstChild('ScreenGui').TextLabel.texty.Value -= 10
local oldPos = game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name).HumanoidRootPart.Position
local newPos = game.Workspace.Checkpoints:FindFirstChild("Checkpoint" .. tostring(tonumber(game.Players.LocalPlayer:FindFirstChild("PlayerGui").ScreenGui.TextLabel.texty.Value) - 10)).Position
oldPos = newPos
end)
I get the error message: " Players.lietherman978.PlayerGui.ScreenGui.TextLabel.ButtonsMainScript2:11: attempt to index nil with ‘Position’ " when i try to go past 11
Because you didn’t do what I said, make 1 invisible brick called Endpoint and define it like local Endpoint = game.Workspace.EndPoint
Then for the code do
local oldPos = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
local newPos = EndPoint.CFrame
oldPos = newPos
Why can’t I use the checkpoint bricks as the invisible brick?
It even printed out the intended checkpoint
Ok at this point, I am just going to start a new thread, this time about the teleporting issue and hopefully more clearer to people.