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 4 years ago

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

001local UserInputService = game:GetService("UserInputService")
002local doors = game.Workspace.Doors:GetChildren()
003local player = game.Players.LocalPlayer
004local slow = 0
005 
006local function onInputBegan(InputObject, gameProcessedEvent)
007    for i , v in pairs(doors) do
008        local open = v.open.Value
009        if math.ceil((v.Part.Position - player.Character.Head.Position).Magnitude) <= 10 then
010            if InputObject.KeyCode == Enum.KeyCode.E and open == 0 then
011                local doormodel = v
012                v = doormodel
013                local door = doormodel.Part
014                local X = door.Position.X
015                local endX = X - 2.9
View all 121 lines...
0
is it a local script? Killerbot712 47 — 4y
0
yes ufiduduj 19 — 4y
0
Does it return any errors? Nckripted 580 — 4y
0
no ufiduduj 19 — 4y
0
We both answered. I hope you can get it work! Killerbot712 47 — 4y

2 answers

Log in to vote
0
Answered by
Nckripted 580 Moderation Voter
4 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:

1local 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:

1open = 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:

1local open = v.open

And then, on line 38, put:

1open.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 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 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

1script.Parent.MouseButton1Click:Connect(function()
2 
3    game.ReplicatedStorage.RemoteEvent:FireServer()
4 
5 
6    end)

and then in a server script you would write

1game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
2player.leaderstats.Cash.Value = player.leaderstats.Cash.Value +1
3end)
0
Anything in ServerStorage can't be seen by the client Leamir 3138 — 4y
0
alr thanks lol. Just wasntt completely sure Killerbot712 47 — 4y

Answer this question