Having trouble referencing something in the workspace from starter Gui

I have a script in a text button in starter gui that detects if its clicked. Upon click, it gets the already confirmed to exist vehicle seat that the player who clicked is sitting on and sends the car model the seat is in to a server script in this one via a remote event. In the server script, it flips the car, because this is supposed to be a flip car button. Apparently I can print the name of the model and the model itself in the server script, but anything about the model is seemingly nil. Including primary part, which is what I use to orient the car on flip. Is there a way to make a flip button different, or is there a way to prevent it becoming nil?

This is the local script that has the server script parented to it.

Player = game.Players.LocalPlayer

Player.Character.Humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
	script.Parent.Visible = not script.Parent.Visible
end)

script.Parent.MouseButton1Click:Connect(function()
	local Model = Player.Character.Humanoid.SeatPart.Parent.Parent
	script.Flip:FireServer(Model)
	game.SoundService.Select:Play()
end)

This is the server script

script.Parent.Flip.OnServerEvent:Connect(function(player: Player, Model)
	local AngleZ = -Model.PrimaryPart.Orientation.Z
	local AngleX = -Model.PrimaryPart.Orientation.X
	Model:PivotTo(Model:GetPivot() * CFrame.Angles(math.rad(AngleX), 0, math.rad(AngleZ)))
	Model:PivotTo(Model:GetPivot() + Vector3.new(0,20,0))
end)
1 Like

Rather than passing the Model at all, try having the Server Script get it from Humanoid.SeatPart.

This also prevents exploiters from passing in something arbitrary to that parameter:

-- Local Script
Player = game.Players.LocalPlayer

Player.Character.Humanoid:GetPropertyChangedSignal("Sit"):Connect(function(sitting)
	script.Parent.Visible = sitting -- I'd also recommend this change
end)

script.Parent.MouseButton1Click:Connect(function()
	script.Flip:FireServer()
	game.SoundService.Select:Play()
end)
-- Server Script
script.Parent.Flip.OnServerEvent:Connect(function(player: Player)
	local Model = Player.Character.Humanoid.SeatPart.Parent.Parent
	if not Model then return end

	local AngleZ = -Model.PrimaryPart.Orientation.Z
	local AngleX = -Model.PrimaryPart.Orientation.X
	Model:PivotTo(Model:GetPivot() * CFrame.Angles(math.rad(AngleX), 0, math.rad(AngleZ)))
	Model:PivotTo(Model:GetPivot() + Vector3.new(0,20,0))
end)

Your solution worked about half of the way or less, it lead me to mine. but yea I kinda figured it out myself for the most part. thanks though.

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