Hi
I have a script in a part (called ship) which uses a tween to move it between point A and B. The ship successfully executes the tween. Here is the code:
local part = script.Parent
local TweenService = game:GetService("TweenService")
local sapphirePosition = workspace.ores.sapphire.Position
while true do
travel_time = workspace.ships.sapphire_collector.ship.movement_script.travel_time.Value
local info = TweenInfo.new(
travel_time,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut,
0,
true,
0
)
local goal = {Position = Vector3.new(sapphirePosition.X, sapphirePosition.Y+3, sapphirePosition.Z);}
local runTween = TweenService:Create(part, info, goal)
runTween:Play()
print(travel_time)
wait(travel_time*2)
wait()
end
I also have a LocalScript inside a TextButton inside a ScreenGUI inside the StarterGUI folder. I use this GUI button to increment a NumberValue called travel_time by 1. This NumberValue is a child of the ship's tween script. The GUI successfully increments the NumberValue. Here is the GUI's script:
local button = script.Parent
local travel_time = workspace.ships.sapphire_collector.ship.movement_script.travel_time.Value
function onButtonActivated()
travel_time = travel_time+1
workspace.ships.sapphire_collector.ship.movement_script.travel_time.Value = travel_time
print(travel_time)
end
button.Activated:Connect(onButtonActivated)
The problem: When I click the button to increase the travel_time NumberValue, it appears the ship's script isn't seeing the changed value and the tween's "time" property isn't increasing, even though I've set it to recheck the NumberValue each time the tween is played.
In other words: The NumberValue is definitely incrementing correctly, but the tween script isn't seeing it and only prints the default value set by the NumberValue which is 2.
I'm probably overlooking something with my lack of experience. Any thoughts?
EDIT 2:
LocalScript:
local Button = script.Parent
local TravelTime = workspace.Ships.SapphireCollector.Ship.MovementScript.TravelTime.Value
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- retrieve the ReplicatedStorage instance
local UpdateEvent = ReplicatedStorage.UpdateValue -- store the UpdateValue event as a variable
function onButtonActivated()
UpdateEvent:FireServer(TravelTime) -- sends a message to the server through the RemoteEvent
end
Button.Activated:Connect(onButtonActivated)
Server Script:
local Part = script.Parent
local TweenService = game:GetService("TweenService")
local SapphirePosition = workspace.Ores.Sapphire.Position
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateEvent = ReplicatedStorage.UpdateValue
UpdateEvent.OnServerEvent:Connect(function(player,TravelTime) -- receiver for the RemoteEvent
TravelTime += 1
print(TravelTime)
end)
while true do
TravelTime = workspace.Ships.SapphireCollector.Ship.MovementScript.TravelTime.Value
local Info = TweenInfo.new(
TravelTime,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut,
0,
true,
0
)
local Goal = {Position = Vector3.new(SapphirePosition.X, SapphirePosition.Y+3, SapphirePosition.Z)}
local RunTween = TweenService:Create(Part, Info, Goal)
RunTween:Play()
print(TravelTime)
wait(TravelTime*2)
wait()
end
Now my TravelTIme NumberValue won't update. Can't figure out why :/

4 comments
Ok so I've implemented the changes, and the travel_time NumberValue won't increment now. No errors in Output. Please see original post's "Edit" for my updated code. It's basically the same as your code though.
Ah, there's the issue. Line 9, you forgot to write .Value after travel_time in the Server Script.
Then I get "Workspace.Ships.SapphireCollector.Ship.MovementScript:9: attempt to index number with 'Value' " error in Output. Because TravelTime is already pointing to that Value right?
Oh man, I'm stupid. You only want to pass the travel_time object, since passing the value is the same as simply passing a number. I'll edit the post to fix that. Hopefully that fixes the issue if you haven't already solved it. Sorry, I should've checked back earlier, that's on me.