When the character walks onto a block the following code should trigger. In studio it works, but when published it does not.
local cop = "Cop" local copCars = {"Car Chassis", "1992 WVD Masamune 3.2 GT"} local cars = {"'54 Caddy", "2015 BMW 435i", "G500", "KZ Converge", "Q7", "Wrangler Rubicon"} function spawnVehicle() local player = game.Players.LocalPlayer local car = "" if player.hasVehicle.Value == 1 then print("Player already has car") else print ("player does not have car") player.hasVehicle.Value = 1 if player.TeamColor == game.Teams[cop].TeamColor then car = copCars[math.random(1,#copCars)] else car = cars[math.random(1, #cars)] end print(car.. " was randomly choosen") local model = game.ServerStorage[car]:clone() model.Parent = game.Workspace model:MakeJoints() model:MoveTo(script.Parent.Parent.Position) waitForNextCar(player) end end function waitForNextCar(player) local i = 1 while i < 10 do wait(1) i = i + 1 end player.hasVehicle.Value = 0 end function onHit(hit) if hit.Parent:WaitForChild("Humanoid") then spawnVehicle() end end script.Parent.Touched:connect(onHit)
TO DO 1) Disable Filtering Enabled (workspace's property), 2) Place script on serverside and use function from Ad2, 3) Place code in script and use function from Ad2.
NOTES:
Ad1. If Filtering Enabled is on then You cant access clientside on serverside and serverside on clientside
Ad2. If script is placed on serverside then You cant use game.Players.LocalPlayer
, try game.Players:GetPlayerFromCharacter
function instead.
Ad3. If script is normal script then You cant use game.Players.LocalPlayer
, try changing script to localscript
If have got any more questions then feel free to write comment
PS: If thing work on studio then try first disabling Filtering Enabled and then check cause it may be because it.