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

[FIXED MYSELF] TextLabel.Text does not change, why?

Right here I have a script that changes textlabel.Text depending on what type of building is present on a grid. However the textlabel does not change. It was blank before the script and stayed blank after the script. print("Changed Text") does print out.

"print(building)" prints out "Miner" (a model)

"print(building.Name)" prints out "Miner" (a string)

textlabel = script.Parent
text = textlabel.Text
rp = game:GetService("ReplicatedStorage")
editevent = rp:WaitForChild("EditEvent")
localplayer =  game.Players.LocalPlayer


editevent.OnClientEvent:connect(function(player, grid, typebuilding)
	textlabel.Parent.Parent.Enabled = true
	if player.Name == localplayer.Name then
		local building = typebuilding.Value
		print(building)
		text = building.Name
		print(building.Name)
		print("Changed Text")
	end
end)

2 answers

On a OnClientEvent remote event call, you can't label the player in the parameters if the event is firing specifically to that client.

Btw, your code looks sloppy, and your variables should use local instead of Global variables.

Here's your fixed code:

local textlabel = script.Parent
local text = textlabel.Text
local rp = game:GetService("ReplicatedStorage")
local editevent = rp:WaitForChild("EditEvent")
local localplayer =  game.Players.LocalPlayer


editevent.OnClientEvent:connect(function(grid, typebuilding)
    textlabel.Parent.Parent.Enabled = true
    local building = typebuilding.Value
    print(building)
    text = building.Name
    print(building.Name)
    print("Changed Text")
end)

Hope this helps :)

2 comments

0

Thanks for your effort, but nothing changed. The thing is, I don't want this text to change for every single player. So that's why I included player in the parameters.

0

Also, it doesn't really matter if it's local or global.

Fixed it myself.

This was my script eventually for the people wondering:

textlabel = script.Parent
rp = game:GetService("ReplicatedStorage")
editevent = rp:WaitForChild("EditEvent")
localplayer =  game.Players.LocalPlayer


editevent.OnClientEvent:connect(function(player, grid, typebuilding)
    textlabel.Parent.Parent.Enabled = true
    if player.Name == localplayer.Name then
        local building = typebuilding.Value
        print(building)
        textlabel.Text = building.Name
        print(building.Name)
        print("Changed Text to", building.Name)
    end
end)

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