I created a script for my tycoon system which will tween a model up from the ground, the object the player is purchasing by stepping on the button will be moved from the tycoons temporary storage in ReplicatedStorage to workspace and the position will be reduced by 1 stud on the y-axis and tweened upwards by 1 stud to give it the effect of being built, the only issue is that when reducing the position of the model it lowers the position by around 10 studs instead of 1, I have no idea why this is happening and have tried so much to fix this.
local tycoon = script.Parent.Parent
local tycoonTemp = game.ServerStorage.TycoonTemp:FindFirstChild(tycoon.Name)
local buttons = tycoon.Buttons
local tweenService = game:GetService("TweenService")
for i, button in pairs(buttons:GetChildren()) do
button.Trigger.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local object = button.Object.Value
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if button.Price.Value <= player.leaderstats.Cash.Value then
for _, buttonPart in pairs(button:GetChildren()) do
if buttonPart:IsA("BasePart") then
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local propertiesToChange = {Transparency = 1, Position = buttonPart.Position + Vector3.new(0, -0.3, 0)}
local buttonFade = tweenService:Create(buttonPart, tweenInfo, propertiesToChange)
buttonFade:Play()
end
end
button.Trigger.Details.Enabled = false
object.Parent = tycoon.Purchases
-- tweening starts here
for i, part in pairs(object:GetDescendants()) do
if part:IsA("BasePart") then
part.Position = part.Position - Vector3.new(0, 1, 0)
part.Transparency = 1
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local propertiesToChange = {Transparency = 0, Position = part.Position + Vector3.new(0, 1, 0)}
local modelFadeIn = tweenService:Create(part, tweenInfo, propertiesToChange)
modelFadeIn:Play()
end
end
object.Purchased.Value = true
else
print("Cannot afford")
end
end
end)
end