Unable to cast Dictionary to Vector3

Why is this happening

UIS.InputChanged:Connect(function(input)
	if player:DistanceFromCharacter(Vector3) > 10 then
			local item = mouse.target

			PickupInfoGui.Adornee = item
			PickupInfoGui.FtoPickup.Text = ":"..item.Minutes.Value.." Minutes to get "..item.Parent.Name
1 Like

What is in your Vector3 thing

put ur item’s primary part’s position in the “vector3”

not really sure someone told me to use player:DistanceFromCharacter(Vector3) Because i was trying get the object by going near it instead of putting your mouse on it but im not sure how to do that

1 Like

now it just complete spams the output with errors like so many in like 1 minute

1 Like

I used that before…Ok I have to study it again…If i find solution i will reply…

local Player
if Player:DistanceFromCharacter(item.PrimaryPart.Position).Magnitude > 10 then
    -- Code --
end

now check if it works…

Is Vector3 a dictionary? Show what’s in the Vector3 variable. If you want to check if the player is close to something, you need to give it a position of what you want to compare to

1 Like

it is still spamming, i want it so this code only registers when the player is near an object that is in a folder.

How do i make it so this works only when a player is near an object in a folder

If Vector3 is a variable, Change the name.

Instead try do:

Vector3.new(Item.Position) 

The vector3 is a point where you want to get the distance from, Vector 3 > 10 wont work because 1, There is no y axis value and there is only a x axis value.

Change you’re code to this:

UIS.InputChanged:Connect(function(input)
	if player:DistanceFromCharacter(Vector3.new(--You're point.) > Vector3.new(-- PartPosition)  then
			local item = mouse.target

			PickupInfoGui.Adornee = item
			PickupInfoGui.FtoPickup.Text = ":"..item.Minutes.Value.." Minutes to get "..item.Parent.Name
                                                      
end

Player:DistanceFromCharacter (roblox.com)

what do i put for your point? and partPosition

item.Position is what you should put for the point

For part position position put where you’re maximum distance is in a vector3 format such as:

Vector3.new(7,7,7)

Item.Position is already a Vector3 value, Vector3.new is for creating a new Vector3 from an X, Y, and Z value.

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

UIS.InputBegan:Connect(function(input, gpe)
    if input.KeyCode == Enum.KeyCode.E and not gpe then -- if the player presses E and they're not typing or anything then
        local selectedItem = Mouse.Target and Mouse.Target or nil
        if selectedItem ~= nil and selectedItem then

            print(Player:DistanceFromCharacter(selectedItem.Position))
           if Player:DistanceFromCharacter(selectedItem.Position) <= 10 then --LESS THAN 10, NOT greater.
                
           end
        end
    end
end)

When you press E with your mouse over an item, this will now print the distance between the item and the character. Hopefully you can learn from this and apply this to your own script, I’d help you more if you could provide more context to the situation

1 Like

Oh now it printed 5

That should be a local script by the way, it will print the distance from the part and the character, so you can now use the distance to determine whether or not the part should be picked up.