I’m pretty new to Lua scripting. I am just getting into developing my own scripts instead of watching a YouTube tutorial or looking on the Developer Forum. I am sorry if this seems to be a question with an obvious answer.
I have a problem in my game. I made my gamepass give mobile users a separate grappling hook than PC users. This is due to a huge bug that I have no clue how to fix right now. The script works perfectly, but I cannot figure out how to remove the PC grappling hook from a mobile player’s inventory. Here is the script:
local MarketPlaceService = game:GetService(“MarketplaceService”)
local GamepassID = 17967553 – The Gamepass ID
local ismobile = game:GetService(‘UserInputService’).TouchEnabled – Detects if a user is on mobile
game.Players.PlayerAdded:Connect(function(player)
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then -- Checking if the user has the gamepass
game.ServerStorage.GrappleGun:Clone().Parent = player:WaitForChild("Backpack")
game.ServerStorage.GrappleGun:Clone().Parent = player:WaitForChild("StarterGear")
if ismobile then -- If the user is on mobile/owns the gamepass, they recieve the mobile grappling hook
game.ServerStorage.ImprovedGrappleHook:Clone().Parent = player:WaitForChild("Backpack")
game.ServerStorage.ImprovedGrappleHook:Clone().Parent = player:WaitForChild("StarterGear")
end
end
You could just add a else statement if the Player is on a different device?
local MarketPlaceService = game:GetService(“MarketplaceService”)
local GamepassID = 17967553 – The Gamepass ID
local ismobile = game:GetService(‘UserInputService’).TouchEnabled – Detects if a user is on mobile
game.Players.PlayerAdded:Connect(function(player)
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then -- Checking if the user has the gamepass
if ismobile then -- If the user is on mobile/owns the gamepass, they recieve the mobile grappling hook
game.ServerStorage.ImprovedGrappleHook:Clone().Parent = player:WaitForChild("Backpack")
game.ServerStorage.ImprovedGrappleHook:Clone().Parent = player:WaitForChild("StarterGear")
else
game.ServerStorage.GrappleGun:Clone().Parent = player:WaitForChild("Backpack")
game.ServerStorage.GrappleGun:Clone().Parent = player:WaitForChild("StarterGear")
end
end
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then -- Checking if the user has the gamepass
if ismobile then -- If the user is on mobile/owns the gamepass, they recieve the mobile grappling hook
game.ServerStorage.ImprovedGrappleHook:Clone().Parent = player:WaitForChild("Backpack")
game.ServerStorage.ImprovedGrappleHook:Clone().Parent = player:WaitForChild("StarterGear")
else
game.ServerStorage.GrappleGun:Clone().Parent = player:WaitForChild("Backpack")
game.ServerStorage.GrappleGun:Clone().Parent = player:WaitForChild("StarterGear")
end
end
Sorry, I made a typo last night when writing the script. Thank you so much for the help, the script works perfectly now! If you can, please explain how the lines of code you put in work. I am a bit confused about what it exactly does. Thank you!
So, say I want to detect if the Player has an object called a “Banana”
If this player has the Banana, we could go ahead & check that this player has a banana in this inventory using this:
if Player.Backpack:FindFirstChild("Banana") then
print("This player has a banana!")
end
But what if he doesn’t have a banana? What would we do then? We use something called the else statement, which can be used if none of the conditional checks have returned back as valid
if Player.Backpack:FindFirstChild("Banana") then
print("This player has a banana!")
else
print("This player has no banana! :(")
end
This can be handy for checking a lot of things, such as valid confirmation on Tools, double check-ups, and such