This part wont tween from a local script

Hello developers! I am currently making a system which when the player touches a part, a shelf falls over. But i keep getting an error which says “Attempt to index nil with “primarypart””. The local script is in startergui. If anybody could help me, it would be appreciated!

Script that detects when a player touches the part

	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") then
			local person = game.Players:GetPlayerFromCharacter(hit.Parent)
			local shelf1 = script.Parent.Parent.Shelf1
			game.ReplicatedStorage.TriggerTweens:FireClient(person, shelf1)

Local script that tweens (error is in here)

local tweenService = game:GetService("TweenService")
local plr = game.Players.LocalPlayer

local function Fall(shelf1)
	local fall = tweenService:Create(shelf1.PrimaryPart,, Enum.EasingStyle.Quint, Enum.EasingDirection.Out, 0, false, 0), -- error here
		{Rotation = -90})


game.ReplicatedStorage.TriggerTweens.OnClientEvent:Connect(function(plr, shelf1)

“Attempt to index nil with PrimaryPart” is an error which means that the model doesn’t exist/wasn’t found, you should instead use shelf1 to send the PrimaryPart to the LocalScript and not the model itself.

IIRC (please correct me if I’m wrong) you shouldn’t place a LocalScript that moves parts inside of StarterGui because it might not detect the parts correctly, please place this script instead in StarterPlayerScripts.

OnClientEvent:Connect doesn’t pass the Player so you should remove it:

1 Like