Part not tweening to tile

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to learn how to create a system which tweens parts to the tile you click, Unit being the part

  2. What is the issue? Include screenshots / videos if possible!
    I continue to get errors like “Unable to cast to Dictionary”

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Here is my LocalScript:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Tiles = game.Workspace.Tiles

local RemoteEvent = game.ReplicatedStorage.RemoteEvent

Mouse.Button1Down:Connect(function()
	print(Mouse.Target)
	if Mouse.Target:IsA("BasePart") and Mouse.Target:IsDescendantOf(Tiles) then
		local targetPosition = Mouse.Target.Position
		
		RemoteEvent:FireServer(targetPosition)
	end
end)

Here is my ServerScript:

local Unit = game.Workspace.Units.Unit

local RemoteEvent = game.ReplicatedStorage.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(targetPosition)
	local tweenInfo = TweenInfo.new(1)
	local tween = game:GetService("TweenService"):Create(Unit, tweenInfo, targetPosition)
	tween:Play()
end)

What is print(mouse.Target) printing?

Prints stuff like this

Ah. Okay, I’ve got the problem. Where you put targetPosition as the third argument in TweenService:Create(), there is supposed to be a dictionary with all the properties and their new values. The ‘Unable to cast to dictionary’ error you are getting is caused by the fact that the method is expecting a dictionary, not a single value, and it can’t ‘cast’ (or convert) a single value to a dictionary. To learn more about this and how to do it, go to TweenService | Documentation - Roblox Creator Hub and read through the examples.

I tried something like this, but it returned the player instead, was I doing what you were saying? Sorry if I wasn’t, I’m so dumb I wasn’t able to comprehend what you said.

local Unit = game.Workspace.Units.Unit

local RemoteEvent = game.ReplicatedStorage.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(target)
	local tweenInfo = TweenInfo.new(1)
	
	local tween = game:GetService("TweenService"):Create(Unit, tweenInfo, { Position = Vector3.new(target.Position.X, 3, target.Position.Z) })
	tween:Play()
end)

Remote events from Client → Server always pass the player that fires them first, and any extra data later. Change your arguments from (target) to (player, target)

RemoteEvent.OnServerEvent:Connect(function(player, target)

Good catch, thank you!

thanks to you too AkroThorn if you’re reading this

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.