Made a horse spawning system. It works. You can buy horses, you can spawn horses. But you can’t despawn.
I have 0 errors, and it’s all printing correctly except for the pcall.
To clear stuff up and for context:
- I have made a folder for “SpawnedHorses”
- When a player joins, a folder with their name is inserted into “SpawnedHorses”
- The dismount event is for them to be removed from the horse, or else they will be stuck in a weird seat position.
Script here:
SpawnHorseEvent.OnServerEvent:Connect(function(plr, HorseName, Command)
print("Horse Event") --Prints
local OwnHorse = DoTheyOwnTheHorse(plr, HorseName)
if Command == "Despawn" then
print("Despawn") --Prints
print(workspace.SpawnedHorses:FindFirstChild(plr.Name):GetChildren()) --Prints children
for i,v in pairs(workspace.SpawnedHorses:FindFirstChild(plr.Name):GetChildren()) do
success,errorm = pcall((function()
Dismount = v:FindFirstChild("Horse").Dismount:InvokeClient(plr) --Checks if they can dismount
end))
if success then
if Dismount == true then
v:Destroy()
end
else
v:Destroy()
end
end
print(success,errorm) --This does not print
elseif Command == "Spawn" then
print("Spawn")
if OwnHorse == true then
MoveTheHorseToThem(plr, HorseName)
end
end
end)
I’ve already ruled out that the server sees the horse, but I don’t know why it’s not printing.
Is it because of the fact that the client isn’t returning yet and it’s doing it’s own version of infinite yield? (If that’s a possibility.) Anyway, help would be nice.