So, I was making a gamepass, that if you touch this little thing, then it allows you to be teleported to another game. But it always comes up with this error.
This is my script:
local id = 23108485
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local teleportPart = script.Parent
local targetPlaceID = 7606460453 -- Change this to your place ID
-- Require teleport module
local TeleportModule = require(ReplicatedStorage:WaitForChild("TeleportModule"))
script.Parent.Touched:Connect(function(Player, hit)
if game:GetService("GamePassService"):PlayerHasPass(Player, id) then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and not player:GetAttribute("Teleporting") then
player:SetAttribute("Teleporting", true)
-- Teleport the player
local teleportResult = TeleportModule.teleportWithRetry(targetPlaceID, {player})
player:SetAttribute("Teleporting", nil)
end
else
print(Player.Name .. " doesn't have the game pass...")
end
end)
local id = 23108485
--when a player joins the game
game.Players.PlayerAdded:Connect(function()
-- MarketplaceService = mps
local mps = game:GetService('MarketplaceService ')
-- print if the player has the pass
print(mps:UserOwnsGamePassAsync(player.UserId,id))
end)
you got 2 arguments at .Touched event… .Touched event only has 1 argument. and thats called “hit” which is gets the part that touched…
u need to get the player first to check if player has gamepass…
local id = 23108485
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local teleportPart = script.Parent
local targetPlaceID = 7606460453 -- Change this to your place ID
local mps = game:GetService("MarketplaceService")
-- Require teleport module
local TeleportModule = require(ReplicatedStorage:WaitForChild("TeleportModule"))
script.Parent.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if mps:UserOwnsGamePassAsync(player.UserId,id) then
if player and not player:GetAttribute("Teleporting") then
player:SetAttribute("Teleporting", true)
-- Teleport the player
local teleportResult = TeleportModule.teleportWithRetry(targetPlaceID, {player})
player:SetAttribute("Teleporting", nil)
end
else
print(player.Name .. " doesn't have the game pass...")
end
end)
--when a player joins the game
Touched doesn’t provide the player instance, it only gives the hit variable. First check for a humanoid to see if it’s a character, then check if you can get a player, like you did above, like this
if hit.Parent:FindFirstChild("Humanoid") then
if game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
--Prompt gamepass, because we know it's the player.
end
end
local id = 23108485
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local teleportPart = script.Parent
local targetPlaceID = 7606460453 -- Change this to your place ID
local mps = game:GetService("MarketplaceService")
-- Require teleport module
local TeleportModule = require(ReplicatedStorage:WaitForChild("TeleportModule"))
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("RightArm") then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and mps:UserOwnsGamePassAsync(player.UserId,id) then
if player and not player:GetAttribute("Teleporting") then
player:SetAttribute("Teleporting", true)
-- Teleport the player
local teleportResult = TeleportModule.teleportWithRetry(targetPlaceID, {player})
player:SetAttribute("Teleporting", nil)
end
else
print(player.Name .. " doesn't have the game pass...")
end
else
print("MAN NOT")
end
end)
--when a player joins the game
It’s giving the argument error again, what did I do wrong?
Here’s the new script:
local id = 23108485
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local teleportPart = script.Parent
local targetPlaceID = 7606460453 -- Change this to your place ID
local mps = game:GetService("MarketplaceService")
-- Require teleport module
local TeleportModule = require(ReplicatedStorage:WaitForChild("TeleportModule"))
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Right Arm") then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and mps:UserOwnsGamePassAsync(player.UserId,id) then
if player and not player:GetAttribute("Teleporting") then
player:SetAttribute("Teleporting", true)
-- Teleport the player
local teleportResult = TeleportModule.teleportWithRetry(targetPlaceID, {player})
player:SetAttribute("Teleporting", nil)
end
else
print(player.Name .. " doesn't have the game pass...")
end
else
print("MAN NOT")
end
end)
--when a player joins the game