Hi, I’m trying to make a Teleportation GUI for my Clicker Game, but the script doesn’t work, here’s my script, (Note, I used ChatGPT for this script.)
-- Set the buy price and click requirement
local buyPrice = 100 -- Change this to the desired buy price
local clickRequirement = 100 -- Change this to the desired click requirement
-- Variable to keep track of whether button has been clicked
local buttonClicked = false
-- Function to handle "GO" button click
local function onGoClicked()
-- Add your desired action here when "GO" button is clicked
print("GO button clicked!")
-- Get the player
local player = game.Players.LocalPlayer
-- Teleport the player to the desired location
local teleportTo = Vector3.new(-53.99, 1.671, 15.125) -- Replace x, y, z with the actual coordinates of the desired teleport location
player.Character.HumanoidRootPart.CFrame = CFrame.new(teleportTo)
end
-- Function to handle button click
local function onButtonClicked()
-- Get the button
local button = script.Parent
-- Check if button has already been clicked
if buttonClicked then
return
end
-- Get the scrolling frame
local scrollingFrame = button.Parent
-- Get the frame
local frame = scrollingFrame.Parent
-- Get the screen GUI
local screenGui = frame.Parent
-- Get the player
local player = game.Players.LocalPlayer
-- Check if player has a 'leaderstats' object
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
-- Get the player's clicks from leaderstats
local clicks = leaderstats:FindFirstChild("Clicks")
-- Check if player has enough clicks to buy the location
if clicks and clicks.Value >= buyPrice then
-- Subtract the buy price from player's clicks
clicks.Value = clicks.Value - buyPrice
-- Change button text to "GO"
button.Text = "GO"
-- Set buttonClicked to true to prevent further actions
buttonClicked = true
-- Call the onGoClicked function
onGoClicked()
end
end
end
-- Connect button click event to onButtonClicked function
script.Parent.MouseButton1Click:Connect(onButtonClicked)
There’s my script, can anybody help me?
(By the way, there’s no errors in output.)
-- Set the buy price and click requirement
local buyPrice = 100 -- Change this to the desired buy price
local clickRequirement = 100 -- Change this to the desired click requirement
-- Variable to keep track of whether button has been clicked
local buttonClicked = false
-- Function to handle "GO" button click
local function onGoClicked()
-- Add your desired action here when "GO" button is clicked
print("GO button clicked!")
-- Get the player
local player = game.Players.LocalPlayer
-- Teleport the player to the desired location
HumanoidRootPart.Position = Part.Position -- Replace x, y, z with the actual coordinates of the desired teleport location
player.Character.HumanoidRootPart.CFrame = CFrame.new(teleportTo)
end
-- Function to handle button click
local function onButtonClicked()
-- Get the button
local button = script.Parent
-- Check if button has already been clicked
if buttonClicked then
return
end
-- Get the scrolling frame
local scrollingFrame = button.Parent
-- Get the frame
local frame = scrollingFrame.Parent
-- Get the screen GUI
local screenGui = frame.Parent
-- Get the player
local player = game.Players.LocalPlayer
-- Check if player has a 'leaderstats' object
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
-- Get the player's clicks from leaderstats
local clicks = leaderstats:FindFirstChild("Clicks")
-- Check if player has enough clicks to buy the location
if clicks and clicks.Value >= buyPrice then
-- Subtract the buy price from player's clicks
clicks.Value = clicks.Value - buyPrice
-- Change button text to "GO"
button.Text = "GO"
-- Set buttonClicked to true to prevent further actions
buttonClicked = true
-- Call the onGoClicked function
onGoClicked()
end
end
end
-- Connect button click event to onButtonClicked function
script.Parent.MouseButton1Click:Connect(onButtonClicked)
It doesn’t work, and I get this in the Output: 18:59:42.743 Players.PowerArmor2020.PlayerGui.ScreenGui.Frame.ScrollingFrame.TextButton.LocalScript:17: attempt to index nil with ‘Position’ - Client - LocalScript:17
assuming that this is a local script there is a problem.
-- Check if player has enough clicks to buy the location
if clicks and clicks.Value >= buyPrice then
-- Subtract the buy price from player's clicks
clicks.Value = clicks.Value - buyPrice
...
end
when you are talking a value away it should be done in the server, hence you would need to use remote events