You could use Remote Events to achieve this. However looking at your current code there may be easier ways to achieve what you’re trying to do. Could you go more in depth on what you’re planning to use this for?
Currently I’m trying to make a Halloween game where you can use a proximity event to give you an amount of candy, however, I am not able to access the localscript to show the player how much candy they have from the regular script. I hope this makes sense.
Are your Guis on the server? Always could change the Text from the Player.PlayerGui.ScreenGui.Frame.Textlabel.Text on the server, other way would be using remote events like @alphadoggy111 said or by using a value managed by the server to the client and detecting when the value changes on the client (server to client does indeed work)
Make a value in the player and then store that in the local script. And then the player can’t see it, but it technicality can carry over when you do the:
As previously stated here, it would be a smarter idea to scratch the entire variable transfer idea and go with something more constant, like the example DevKeia gave. Because you’re redesigning the entire system though, I wanted to give at least a basic understanding of how it could potentially look! I’ve tried my best to add consistent comments throughout this to hopefully help explain the topics better.
Server script:
game.Players.PlayerAdded:Connect(function(plr) -- all the code here is going to add a folder named private, as well as add a value named candy in that folder for each player.
local PrivateStats = Instance.new("Folder")
PrivateStats.Name = "Private"
PrivateStats.Parent = plr
local candyValue = Instance.new("IntValue")
candyValue.Name = "Candy"
candyValue.Parent = PrivateStats
end)
workspace.Part.ProximityPrompt.Triggered:Connect(function(plr) -- your previous Triggered function. I've left this in the same script however for best practice sake I'd probably move this to another script but in terms of base functionality this should be fine.
plr.Private.Candy.Value += 1
end)
Local script:
local player = game.Players.LocalPlayer
local privateFolder = player:WaitForChild("Private")
local candyValue = privateFolder:WaitForChild("Candy")
candyValue.Changed:Connect(function()
script.Parent.Text = candyValue.Value .. " Candies" -- script.Parent.Text would become the path to the UI. If this script is right below the text you want to change in the ancestry, you can leave this the same.
end)
Hopefully this not only points you in the right direction but also helps you understand the concept better.