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

Why does this value, when changed, still print the old one? (TextBox)

I have a semi-longish script for an experiment. A local one and a server one. I'm testing one local one so I wouldn't have to send all the other locals because they are almost the exact same.

I'll show you what is wrong with the script(s).

LocalScript:

local ReplicatedStorage = game.ReplicatedStorage
local Event = ReplicatedStorage.Xlockevent
local Pos = script.Parent.Parent.Xpos.Text -- This might be the part that you should focus on.... It does look innocent, though.
local enabled = false
local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if enabled == false then
		enabled = true
		script.Parent.Style = "RobloxRoundDefaultButton"
		Event:FireServer(enabled, Pos)
	elseif enabled == true then
		enabled = false
		script.Parent.Style = "RobloxRoundButton"
		Event:FireServer(enabled, Pos)
	end
end)

ServerScript (Go to line 20!)

local ReplicatedStorage = game.ReplicatedStorage
local ServerStorage = game.ServerStorage
local brick = ServerStorage.SpawnBrick
local ypos = false
local yposn = nil 
local xpos = false
local xposn = nil
local zpos = false
local zposn = nil
local on = true
local ox = 0
local oy = 0
local oz = 0
ReplicatedStorage.Ylockevent.OnServerEvent:Connect(function(plr, enabled, Pos)
	print("Yfired")
	if enabled == true then
		ypos = true
		yposn = Pos
		print(Pos) -- When I tried to print it, it printed "Enter Y position" in the Text Box, instead of 2  the that I entered when I was testing (It was "Enter Y position" and then I changed it to 2 when I was testing(entering 2 in the text box)).
	end
end)
ReplicatedStorage.Xlockevent.OnServerEvent:Connect(function(plr, enabled, Pos)
	print(enabled)
	if enabled == true then
		xpos = true
		xposn = Pos
	end
end)
ReplicatedStorage.Zlockevent.OnServerEvent:Connect(function(plr, enabled, Pos)
	if enabled == true then
		zpos = true
		zposn = Pos
	end
end)
ReplicatedStorage.BuildEvent.OnServerEvent:Connect(function(plr, MouseHit)
	if on ~= true then return end
	local cbrick = brick:Clone()
	cbrick.Parent = workspace
	print(xpos)
	print(ypos)
	print(zpos)
-- The rest is kinda.. Sloppy... Don't have to read this word by word; it has nothing to do with it. However it's glitched because of that value not changing.
	if ypos == true and xpos ~= true and zpos ~= true then -- Y only
		
		cbrick.CFrame = CFrame.new(MouseHit.X, yposn, MouseHit.Z)
		
	elseif xpos == true and ypos ~= true and zpos ~= true then -- X position only
		cbrick.CFrame = CFrame.new(xposn, MouseHit.Y, MouseHit.Z)
		
		
	elseif zpos == true and ypos ~= true and xpos ~= true then
		cbrick.CFrame = CFrame.new(MouseHit.X, MouseHit.Y, zposn) -- Z position only
		
		
	elseif zpos == true and ypos == true and xpos ~= true then -- Z and Y positions
		cbrick.CFrame = CFrame.new(MouseHit.X, yposn, zposn)


	elseif zpos == true and ypos == true and xpos == true then -- All positions
		cbrick.CFrame = CFrame.new(xposn, ypos, zposn)
		
		
	elseif zpos == true and ypos ~= true and xpos == true then -- X and Z positions
		cbrick.CFrame = CFrame.new(xposn, MouseHit.Y, zposn)
		
		
	elseif zpos ~= true and ypos == true and xpos == true then -- Y and X positions
		cbrick.CFrame = CFrame.new(xposn, yposn, zposn)
	else -- Anything else
		cbrick.CFrame = MouseHit 
	end
	cbrick.Orientation = Vector3.new(ox, oy, oz)
end)

1 comment

0

Plus, there are no errors

1 answer

✓ Accepted answer

This is because you're setting it up in a variable and the variable keeps information about its current text RIGHT NOW. That's like doing this:

local testingNumber = 42

print(testingNumber)--Why is this not printing 32!!
testingNumber = 32

So, It will be better to set the variable inside of the MouseButton1Click event. It's going to keep data of its text whenever it's clicked

4 comments

0

Thanks! It worked! It's kinda weird I didn't know it was THAT simple.

0

Did it go back before I posted this problem?

0

Wait no, it's a problem with the serverscript.

0

I was dumb enough to put "enabled=false" in the MouseButton1Click.. xD.. Now i'm looking for the problem in the server script.

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