So this is my most recent attempt at creating my script before I gave up and decided to come on here. My script is supposed to when the player presses the "M" key spawn their mount, and if their mount is out and they press M again it'll be removed.
This attempt does not work.
I already checked and the event gets fired and received, and the script kind of works. The script will spawn their mount (in this case a snake) just fine, but when the player pressed M again to despawn it, it never worked, that or it did but had a complication. I tried using a global variable for the mount's model, but that made everyone share 1 mount which was not good for my open world game. The attempt you see is where I read I could use the return feature with the variable and it would make it usable by the rest of the script. After this failed, I gave up.
I want to be able to clone and place a different copy of the mount each time and :Remove() it once the event is fired again. Please help!
Server Script:
game.Players.PlayerAdded:Connect(function(plr) -- This adds a debounce for later
local hasMount = Instance.new("BoolValue")
hasMount.Name = "hasMount"
hasMount.Parent = plr
hasMount.Value = false
end)
game.ReplicatedStorage.Events.MountCall.OnServerEvent:Connect(function(plr) -- The actual function
local Stuff = plr:WaitForChild("Stuff") -- The folder I keep everything for the player in
local Mount = Stuff:WaitForChild("Mount") -- A string value telling the game which mount the player has
local hasMount = plr:WaitForChild("hasMount") -- the debounce mentioned earlier
if Mount.Value == "Snake" then -- Makes sure they own the mount
if hasMount.Value == false then -- makes sure the mount isn't out already
hasMount.Value = true
local model = game.ServerStorage.Mounts:WaitForChild("Snake Mount") -- The physical mount
model.Parent = workspace
model.HumanoidRootPart.CFrame = plr.Character.HumanoidRootPart.CFrame + Vector3.new(0,4,6)
return model -- What I thought would help
elseif hasMount.Value == true then -- The part of the function I need to share the variable with
hasMount.Value = false
model:Remove()
end
-- More Mounts Slot
end
end)
I've been trying to solve this all day. I would really appreciate a response. Thanks in advance!

1 comment
Incase I wasn't clear (I suck at explaining) I'm trying to: If hasMount.Value == true then remove the existing model