so yes, I found a script in free models, but I want to modify it a little bit, I somewhat understand how this script works, but I can not figure out how to modify it to get it to do what I want it to do

so basically,

this is a tool that allows you to click anywhere within the workspace and it spawns a car from serverstorage, however I am trying to make it so instead of click anywhere you have to click on a certain brick, for example if the player clicks a brick named "carspawn" the car then spawns on the brick. I been at this for an hour trying to figure out how to and I just can't

server script

local CarSpawn = game:GetService("ReplicatedStorage"):WaitForChild("CarSpawner")
local CarDestroy = game:GetService("ReplicatedStorage"):WaitForChild("CarDestroyer")
local ServerStorage = game:GetService("ServerStorage")

CarSpawn.OnServerInvoke = function(Player,x,y,z,name)
	local car = ServerStorage:WaitForChild("Car")
	if car then
		car.Name = Player.Name.."Car"
		car = car:Clone()
		car.Parent = workspace
		car:MakeJoints()
		car:MoveTo(Vector3.new(x,y,z))
		return car
	end
end

CarDestroy.OnServerEvent:connect(function(Player,Car)
	Car:Destroy()
end)

local script within tool

local DB = false
local Value = script.Parent:WaitForChild("Car")

local Event = game:GetService("ReplicatedStorage"):WaitForChild("CarSpawner")
local Destroy = game:GetService("ReplicatedStorage"):WaitForChild("CarDestroyer")
local UIS = game:GetService("UserInputService")
local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
local Car
local Name = script.Parent.Name

UIS.InputEnded:connect(function(input,gpe)
	if not gpe then
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			if not DB then
				DB = true
				if Car then
					Destroy:FireServer(Car)
				end
				Car = Event:InvokeServer(Mouse.Hit.X,Mouse.Hit.Y + 5,Mouse.Hit.Z,Value.Value)
				for i = 10,1,-1 do
					script.Parent.Name = i
					wait(1)
				end
				script.Parent.Name = Name
				DB = false
			end
		end
	end
end)

2 comments

0

Please write your own scripts this is not a website for requesting or using a script you didn't make. :)

0

I think you would use mouse:hit for this? But that might be decrepit :/