Hello guys, how are you doing? I’m struggling with this one problem in my game. Is there a way to teleport a player to a certain game depending on the item they have on their inventory?
So there’s this game I’m working on and the main goal is to escape your father’s house without him noticing it and head to the party. So one way to escape the house is by using the window, but I want to make it so that when the player uses the window without the item “Rope” in their inventory they will be teleported to a hospital, however if they have a rope in their inventory they will be teleported out of the house.
This is the code:
– Services –
local TeleportService = game:GetService(“TeleportService”)
local sound = workspace.WindowOpen
– Instances –
local ProximityPrompts = script[“Proximity Prompts”]
local Settings = script.Settings
– Variables –
local proximityPrompts = {}
local connections = {}
local placeId = Settings[“Place Id”].Value
local cityid = Settings[“City ID”].Value
– Functions –
local function getProximityPrompts()
for index, child in pairs(ProximityPrompts:GetChildren()) do
if child:IsA(“ObjectValue”) then
local prompt = child.Value
if prompt:IsA(“ProximityPrompt”) then
table.insert(proximityPrompts, prompt)
end
end
end
end
local replicatedstorage = game:GetService(“ReplicatedStorage”)
local teleportdoor = replicatedstorage:WaitForChild(“WindowEvent”)
local function onTriggered(player)
local chr = player.Backpack
if chr:FindFirstChild"Rope" then
sound:Play()
teleportdoor:FireClient(player, true)
TeleportService:Teleport(cityid, player)
elseif not chr:FindFirstChild"Rope" then
sound:Play()
teleportdoor:FireClient(player, true)
TeleportService:Teleport(placeId, player)
end
end
– Code –
getProximityPrompts()
for index, prompt in ipairs(proximityPrompts) do
local connection = prompt.Triggered:Connect(onTriggered)
table.insert(connections, connection)
end
Any kind of help would be appreciated.