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

Why doesn't my number value change when I scripted it to change?

My number value doesn't change whenever the script runs through it. The change is at line 38.

local UserInputService = game:GetService("UserInputService")
local doors = game.Workspace.Doors:GetChildren()
local player = game.Players.LocalPlayer
local slow = 0

local function onInputBegan(InputObject, gameProcessedEvent)
	for i , v in pairs(doors) do
		local open = v.open.Value
		if math.ceil((v.Part.Position - player.Character.Head.Position).Magnitude) <= 10 then
			if InputObject.KeyCode == Enum.KeyCode.E and open == 0 then
				local doormodel = v
				v = doormodel
				local door = doormodel.Part
				local X = door.Position.X
				local endX = X - 2.9
				local Y = door.Position.Y
				local Z = door.Position.Z
				local Z2 = Z
				local endZ = Z + 2.6
				local rotate = door.Orientation.Y
				local angle = math.rad(rotate)
				local angle2 = math.rad(rotate)
				local angleend = angle + math.rad(90)
				if slow == 0 then
					if math.ceil((door.Position - player.Character.Head.Position).Magnitude) <= 10 then
						if rotate == 0 then -- 0 degrees
							while true do
								if angle < angleend and endZ > Z then
									door.CanCollide = false
									door.CFrame = CFrame.new(X + 0.13,Y,Z + 0.155) * CFrame.Angles(0,angle + math.rad(4.5),0)
									angle = angle + math.rad(4.5)
									X = X + 0.13
									Z = Z + 0.155
									wait(0.005)
									slow = 1
								else
									door.CanCollide = true
									open = open + 1
									slow = 0
									wait(0.05)
									break
								end
							end
						elseif rotate == -90 then -- -90 degrees
							while true do
								if angle < angleend and endZ > Z then
									door.CanCollide = false
									door.CFrame = CFrame.new(X - 0.145,Y,Z + 0.13) * CFrame.Angles(0,angle + math.rad(4.5),0)
									angle = angle + math.rad(4.5)
									X = X - 0.145
									Z = Z + 0.13
									wait(0.005)
									slow = 1
								else
									door.CanCollide = true
									open = open + 1
									slow = 0
									wait(0.05)
									break
								end
							end
						end 
					end
				end
			elseif InputObject.KeyCode == Enum.KeyCode.E and open == 1 then	
				local doormodel = v
				v = doormodel
				local door = doormodel.Part
				local X = door.Position.X
				local endX = X - 2.9
				local Y = door.Position.Y
				local Z = door.Position.Z
				local Z2 = Z
				local endZ = Z + 2.6
				local rotate = door.Orientation.Y
				local angle = math.rad(rotate)
				local angle2 = math.rad(rotate)
				local angleend = angle + math.rad(90)
				if math.ceil((door.Position - player.Character.Head.Position).Magnitude) <= 10 then
					if rotate == 90 then -- 0 degrees
						while true do
							if angle > angle2 and Z2 < Z then
								door.CanCollide = true
								door.CFrame = CFrame.new(X - 0.13,Y,Z - 0.155) * CFrame.Angles(0,angle - math.rad(4.5),0)
								angle = angle - math.rad(4.5)
								X = X - 0.13
								Z = Z - 0.155
								slow = 1
								wait(0.005)
							else
								open = open -1
								slow = 0
								wait(0.05)
							break
							end
						end
					elseif rotate == 0 then -- -90 degress
						while true do
							if angle > angle2 and Z2 < Z then
								door.CanCollide = true
								door.CFrame = CFrame.new(X + 0.145,Y,Z - 0.13) * CFrame.Angles(0,angle - math.rad(4.5),0)
								angle = angle - math.rad(4.5)
								X = X + 0.145
								Z = Z - 0.13
								wait(0.005)
								slow = 1
							else
								open = open - 1
								slow = 0
								wait(0.05)
								break
							end
						end
					end
				end
			end
		end
	end
end
	
UserInputService.InputBegan:Connect(onInputBegan)

5 comments

0

is it a local script?

0

yes

0

Does it return any errors?

0

no

0

We both answered. I hope you can get it work!

2 answers

✓ Accepted answer

I would like to elaborate on what Killerbot72 said, except you can change values from a local script. But if you get the value on the server, it will return something else.

Your issue is that on line 8, you said the following:

local open = v.open.Value

This code returned the current value, not the actual object. By this I mean you were just changing the variable, so when you said this:

open = open + 1

You weren't adding on the value's value. You were adding to number variable that wasn't changing anything else.

The fix is that on line 8, put:

local open = v.open

And then, on line 38, put:

open.Value = open.Value + 1

If you refrenced open anywhere else in the script, make sure you are doing your comparisons using open.Value, not open

Hope this helped!

1 comment

0

Would upvote but i cant lol

You can't change values with a local script by itself. So you MUST use remote events

this might help

for example if you wanted to change a value when a player clicks a textbutton you will have to put a RemoteEvent in ReplicatedStorage.

and in the local script inside of the text button you would have to write

script.Parent.MouseButton1Click:Connect(function()

	game.ReplicatedStorage.RemoteEvent:FireServer()


	end)

and then in a server script you would write

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value +1
end)

2 comments

0

Anything in ServerStorage can't be seen by the client

0

alr thanks lol. Just wasntt completely sure

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