Vehicle Script Help

I need some help with my script, I would like the Owner value to be set to the Player’s Name and the OwnerId value set to the Player’s UserId, But I can’t get it. Can somebody help please?

local enabled = false

local function spawnVehicleForPlayer(Player)
	if enabled == false then
		enabled = true
		local Mod = game.ServerStorage.Vehicles['Lamborghini Aventador']
		local clone = Mod:Clone()
		clone.Parent = workspace.Vehicles
		local ControlValues = clone:WaitForChild("Control_Values")
		ControlValues.Owner.Value = Player.Name
		ControlValues.OwnerId.Value = Player.UserId
		clone:MakeJoints()
		wait(25)
		enabled = false
	end
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		spawnVehicleForPlayer(Player)
	end)
end)

script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	spawnVehicleForPlayer(player)
end)
1 Like

And I am only using that vehicle for testing, It won’t be in the game, It was the first vehicle I saw in my inventory

Is this a LocalScript or a server script?

Server Script within the TextButton

Why? Does it need to be a Local Script?

Here you’re referencing the player twice, the PlayerAdded event will run fine, however, the local player can’t be called from a server script so the MouseButton1Click wont work as intended.

Are you able to help me rewrite this script?

Never Mind, I got the script working

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