Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Position Change not working?

I'm trying to make it when a mouse is hovered over a part, the script moves a part called "factoryFaded" from ServerStorage to Workspace, and bring its to the coordinates (-25.222, -0.49, -0.554). It isn't working, and the only output I get says "factoryFaded is not a valid member of Part", and "factoryFaded is not a valid member of ServerStorage"

Here is the script

local click = script.Parent

while wait(0.5) do

	click.MouseHoverEnter:connect(function(player) 
    	game.ServerStorage.factoryFaded.Parent = game.Workspace
		game.Workspace.factoryFaded.Position = Vector3.new(-25.222, -0.49, -0.554)
	end)
	click.MouseHoverLeave:connect(function(player)
		game.Workspace.factoryFaded.Parent = game.ServerStorage
	end)
	click.MouseClick:connect(function(player)
    	
	end)
end

1 comment

0

Change Position to CFrame and is the Script a LocalScript?

1 answer

You don't want a while loop as this will keep creating connections which will result in the functions being called multiple times. (Therefore attempting to move the part multiple times resulting in an error).

It's also better to save what you're changing as a variable and manipulate it that way.

local click = script.Parent
local factoryFade = game.ServerStorage.factoryFaded

click.MouseHoverEnter:connect(function(player) 
	factoryFade.Parent = workspace
	-- Now that you have told me factoryFade is a model you have two options:
	
	--factoryFade:MoveTo(Vector3.new(-25.222, -0.49, -0.554))
	--or (if you've set factoryFade.PrimaryPart)
	--factoryFade:SetPrimaryPartCFrame(CFrame.new(-25.222, -0.49, -0.554))
end)

click.MouseHoverLeave:connect(function(player)
	factoryFade.Parent = game.ServerStorage
end)

click.MouseClick:connect(function(player)

end)

2 comments

0

I tried using that, and the output said : "11:25:11.597 - Position is not a valid member of Model 11:25:11.598 - Script 'Workspace.tile1.ClickDetector.Script', Line 6

0

There's your problem, factoryFade is a model and therefore doesn't have a position property, I've edited the script for you.

This discussion is preserved as it was. New answers, comments, and votes are closed.