Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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)
0
is it a local script? Killerbot712 47 — 3y
0
yes ufiduduj 19 — 3y
0
Does it return any errors? Nckripted 580 — 3y
0
no ufiduduj 19 — 3y
0
We both answered. I hope you can get it work! Killerbot712 47 — 3y

2 answers

Log in to vote
0
Answered by
Nckripted 580 Moderation Voter
3 years ago

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!

0
Would upvote but i cant lol Killerbot712 47 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
0
Anything in ServerStorage can't be seen by the client Leamir 3138 — 3y
0
alr thanks lol. Just wasntt completely sure Killerbot712 47 — 3y

Answer this question