Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How could I fix this problem? Is there any way to change player's GUI from a script?

local event = game.ReplicatedStorage.TreeCutEvent
local tree = game.Workspace.Tree
local detector = tree.ClickDetector
local resourcevalue = tree.TreeResource.Value

event.OnServerEvent:Connect(function()
	resourcevalue = resourcevalue + 1
	tree.Transparency = 1
	detector.MaxActivationDistance = 0
	wait(2)
	tree.Transparency = 0
	detector.MaxActivationDistance = 32
	game.StarterGui.ScreenGui.TextLabel.Text = "Wood - ".. resourcevalue
	
end)

This is the script that I'm using and it fires and changes the value, but the GUI doesn't change. I assume this is because I should be using game.Players.LocalPlayer.PlayerGui... but I don't know how to implement this.

The goal is once the value changes, that it should change in the TextLabel as well,

any help is appreciated!

2 comments

0

Yea that will change what a player who has joined the game after the tree has been clicked will see

0

doesnt work for me

2 answers

✓ Accepted answer

Try using ClickDetector.mouseClick.playerWhoClicked. Haven't tested this just yet but it gives an idea of what you should do.

local event = game.ReplicatedStorage.TreeCutEvent
local tree = game.Workspace.Tree
local detector = tree.ClickDetector
local resourcevalue = tree.TreeResource.Value

event.OnServerEvent:Connect(function()
    resourcevalue = resourcevalue + 1
    tree.Transparency = 1
    detector.MaxActivationDistance = 0
    wait(2)
    tree.Transparency = 0
    detector.MaxActivationDistance = 32
    detector.MouseClick.playerWhoClicked.ScreenGui.TextLable.text = "Wood - ".. resourcevalue
end)

Fixed this by doing this..

local event = game.ReplicatedStorage.TreeCutEvent
local tree = game.Workspace.Tree
local detector = tree.ClickDetector
local resourcevalue = tree.TreeResource.Value

event.OnServerEvent:Connect(function(player)
	print "gay"
	game.Workspace.Tree.TreeResource.Value = game.Workspace.Tree.TreeResource.Value + 1
	tree.Transparency = 1
	detector.MaxActivationDistance = 0
	player.PlayerGui.ScreenGui.TextLabel.Text = "Wood - ".. game.Workspace.Tree.TreeResource.Value
	wait(2)
	tree.Transparency = 0
	detector.MaxActivationDistance = 32
	
end)

added the player into function and just went off that! Thanks for anyone who tried to help

This discussion is preserved as it was. New answers, comments, and votes are closed.