local screwnum = 0
local player = game:GetService("Players")
local gui = player:WaitForChild("PlayerGui")
local screws = gui.ScrewUI
screws.ScrewNUM.Text = screwnum
--script.Parent.ProximityPrompt.PromptButtonHoldEnded:Connect(function()
-- print(screwnum)
--end)
while true do
wait(1)
print(screws.ScrewNum.Text)
end
this is what my player looks like in the workspace when i play the game:
Any output? And it is supposed to be print(screws.ScrewNUM.Text) (capitalized NUM).
Edit: You get the LocalPlayer via game:GetService("Players").LocalPlayer. There is also a good possibility ScrewUI is not replicated before the script fires, assuming your script is in the StarterPlayerScripts.
i edited my code keeping everything you said in mind and defined screws inside of the loop (which i know is most likely not good practice, but this is just for testing) and it still is not outputting anything
local screwnum = 0
local player = game:GetService("Players").LocalPlayer
local gui = player:WaitForChild("PlayerGui")
--script.Parent.ProximityPrompt.PromptButtonHoldEnded:Connect(function()
-- print(screwnum)
--end)
while true do
wait(1)
local screws = gui.ScrewUI
screws.ScrewNUM.Text = screwnum
print(screws.ScrewNUM.Text)
end
also, the localscript is under the object i have the proximityprompt in, not localplayerscripts, i was trying to avoid doing that but is that the only way this would be possible?
That is the problem. LocalScripts only runs on descendants of specific containers - it will not run under workspace. Instead, you can either:
Change it into a server-sided Script so it will run, and fire a RemoteEvent that will update the ScreenGui in another LocalScript inside the gui itself.
Move your LocalScript inside your actual ScreenGui and reference the ProximityPrompt.
Change your script into a Script and set the RunContext to Client, essentially running client-sided code that runs in the workspace.
It is recommended to use method 1 over 2 since the ProximityPrompt might not always exist on the client because it might not have loaded yet or is outside the range of streaming. This guarantees the server keeping track of the ProximityPrompt at all times and sending the client the information when needed.
Method 3 might also not be the best method since I am not 100% on how the LocalScript will react if it loads first before the actual Part containing the ProximityPrompt (if assuming it loads that way).
here try this you made some miss Type some names and also in Proximity prompt the PromptButtonHoldEnded is not working so I change it to Triggered. also I change your ways of declaring the paths for the object because your is direct and sometimes can cause and error.
local screwnum = 0
local player = game:GetService("Players")
local gui = player.LocalPlayer:WaitForChild("PlayerGui")
local screws = gui:FindFirstChild("ScrewUI")
game.Workspace:WaitForChild("Folder"):FindFirstChild("Part"):FindFirstChild("ProximityPrompt").Triggered:Connect(function()
screws:FindFirstChild("ScrewNUM").Text = screwnum
screwnum += 1
print(screwnum)
end)
while true do
wait(1)
print(screws:FindFirstChild("ScrewNUM").Text)
end