How can I fix Chat GPT's scripting?

  1. Situation Overview: I am an incredibly amateur scripter, so when I heard people saying the AI program Chat GPT could be used to write roblox scripts I was ecstatic. I tried using it to script a game idea I had called “Corner the Market” in which players are assigned products upon joining the game and have to compete with other players to make the most money. After prompting Chat GPT to create the script I had in mind to assign each player a product and increase their score based on if another player in the game had the product, I was impressed with the result. To me (the amateur scripter) it seemed on the right track; however, it doesnt work at all.

  2. Issue: The script does not increase the player’s “Score” stat every second by either 10 or 5 upon the player joining the game.

  3. Solutions Tried: I added a few lines of code the script to create the leaderboard and Score stat, and made sure the script was placed in ServerScriptService.

game.Players.PlayerAdded:Connect (function(player)

          local stats = Instance.new("IntValue")
          stats.Name = "leaderstats"

          local score = Instance.new("IntValue", stats)
          score.Name = "Score"

stats.Parent = player 
end)

-- Create a table of the four words
local words = {"Clocks", "Fans", "Lamps", "Hats"}

-- Function to assign a word to a player and set up their score tracking
local function assignWord(player)
  -- Assign a random word to the player
  local word = words[math.random(#words)]
  player.Word = word

  -- Set up a score tracking function for the player
  local function trackScore(player)
    -- Increase the player's score by 10 if they are the only one with their word
    if game.Players:GetPlayers(player.Word) == player then
      player.leaderstats.Score.Value = player.leaderstats.Score.Value + 10
    -- Otherwise, increase the score by 5
    else
      player.leaderstats.Score.Value = player.leaderstats.Score.Value + 5
    end
  end

  -- Run the score tracking function every second
  player.Heartbeat:Connect(function()
    trackScore(player)
  end)
end

-- Assign a word to each player when they join the game
game.Players.PlayerAdded:Connect(function(player)
  assignWord(player)
end)

I understand that it could be controversial to use a chat bot to write scripts for you since you don’t have to do much work, but I think it could be a great resource for aspiring scripters like myself.

You should not use ChatGPT whatsoever. You should definitely learn programming yourself.

1 Like

However, to answer your question, the part that is erroring is player.Word; this property doesn’t exist, nor does player.Heatbeat.

    if game.Players:GetPlayers(player.Word) == player then
      player.leaderstats.Score.Value = player.leaderstats.Score.Value + 10
    -- Otherwise, increase the score by 5

this will also throw and error.

Although ChatGPT is a great resource for scripting, you shouldn’t always rely on it. The best thing would be just to learn from it (Minus the errors from the output).

Do not use ChatGPT for code generation, especially because you are an amateur.

Are you sure it’s been an excellent resource for you? ChatGPT’s training ceased in 2021, so it will not be updated with any more upcoming API features. Additionally, it’s just not good for code generation (what is "Player.Heartbeat or “Player.Word??”). Please do not use ChatGPT for generating code. It will only throw you off and hinder the progress of your scripting journey.

image

8 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.