#A Tix/Coin Scripting Problem

161 messages · Page 1 of 1 (latest)

modern harness
#

Hello I need help with my game so I have a Tix/Coin you can call it I want it to do this so when a player touches the Tix/Coin whatever you wanna call it it should disappear and add 1 point in the leaderboard i dont want a gui leaderboard i want a regular leaderboard and if a player rejoins i dont want them to keep grinding in one tix/coin so no respawn Thank you!

autumn mica
#

Um

#

If you want a whole system then #💵︱hiring

#

But I can help you figure it out

modern harness
#

i will apperciate it if you can

#

i tried using ai

#

did not help

autumn mica
#

Can you script well?

modern harness
#

no i am learning

#

but i can type fast

autumn mica
#

💀I don't think that helps much here

modern harness
#

😭ikr

#

so is their anything that i can do

autumn mica
#

Yes

modern harness
#

what is it then 😦

autumn mica
#

Gimme a sec I'm helping someone else

modern harness
#

alr

#

i am gonna be playing roblox for then

#

when you are done mention me okay

#

??

autumn mica
#

Alr

random cosmos
#

show us your code

autumn mica
#

They don't have any

modern harness
#

i dont have any

random cosmos
#

code to make a part disapear on touch and add plus one to a stat?

modern harness
#

no so i want to do is this when a player touches a part they get 1 point right. Then after when they get the point the part disappears and if the player rejoins then they can't keep standing there and keep grinding the same coin

autumn mica
#

@modern harness
Here's the basic idea:

  1. Use some sort of mass scripting (collection service, loops, modules, etc.) to detect a touch

  2. If it's a player, update their leader stats value

  3. Turn off can touch, can collide, etc.

  4. Put that coin in a table with a bool or something that shows that it's been touched by the player.

  5. When a player joins, get the data store and loop through the table setting the touch detections back on

modern harness
#

I dont know anything of about this

autumn mica
random cosmos
#

you will need to learn this is basic stuff

#

potato gave you all the parts

#

you need to learn datastores to store player data

modern harness
#

api

autumn mica
#

its not really basic but it's essential for a cool game ¯_(ツ)_/¯

modern harness
#

is there for datastore

modern harness
autumn mica
#

Probably but you have to check #💵︱hiring or #👷︱for-hire

#

Most people in scripting help won't make scripts for you

modern harness
#

i got no cash

#

😦

autumn mica
#

There's people that work for free

#

There's a role but I'm not sure how it works

#

I have it bc idk how to get rid of it 😭

#

But there's people that actually will script for free

modern harness
#

okay so i go into the hiring

autumn mica
#

I recommend watching tutorials or something tho

random cosmos
#

you could learn this stuff in a weak my dude

autumn mica
#

And follow my outline

cedar summitBOT
#

studio** You are now Level 1! **studio

random cosmos
#

save your money, develop your skills

autumn mica
#

Yeah it's not an easy concept but easy to learn

#

If that makes sense

#

There's tons of resources

modern harness
#

it gets boring

#

thats all

autumn mica
modern harness
#

everytime i do

#

the parts go somwhere random

#

but wait i do have code

#

i have code wait wait

autumn mica
#

Yeah you need a bit of knowledge to fix the code tho

#

AI is inconsistent af

#

Lemme try something

random cosmos
#

you may need to actually learn how coding in general works

modern harness
#

this is the code that i have so far

random cosmos
#

that might help you faster

modern harness
#

how do i put it into

#

the code version in discord

random cosmos
#

3 back ticks

#

before and after the code

#

`

modern harness
#
local pointsDataStore = DataStoreService:GetDataStore("PlayerPoints")

game.Players.PlayerAdded:Connect(function(player)
    local playerId = player.UserId
    local playerKey = "Points_" .. playerId

    -- Load player's points from datastore
    local success, points = pcall(function()
        return pointsDataStore:GetAsync(playerKey)
    end)

    if success then
        -- Create leaderstats if not exists
        local leaderstats = Instance.new("Folder")
        leaderstats.Name = "leaderstats"
        leaderstats.Parent = player

        -- Create Points value
        local pointsValue = Instance.new("IntValue")
        pointsValue.Name = "Points"
        pointsValue.Value = points or 0
        pointsValue.Parent = leaderstats

        -- Save points when player leaves
        player:Connect(function()
            local success, error = pcall(function()
                pointsDataStore:SetAsync(playerKey, pointsValue.Value)
            end)
            if not success then
                warn("Failed to save data: " .. error)
            end
        end)
    else
        warn("Failed to load data for player " .. player.Name)
    end
end)```
random cosmos
#

ok what happens when you run it

modern harness
#

this was in ServerScriptService

random cosmos
#

why? did you make it?

modern harness
#

it works

#

but the problem is

#

when i rejoin

#

the part stays there

random cosmos
#

well the problem is obvious

autumn mica
#

I tried clowning chatgpt but it doesn't work 😭😭

#

Anyways

modern harness
#

image player a was touching it after he got the point the part disappears but after it disappears other people can still see it

cedar summitBOT
#

studio** You are now Level 4! **studio

random cosmos
#

are you starting the server when you join the game?

modern harness
#

like player b can see it

#

yeah

random cosmos
#

does the part get created when the server starts?

modern harness
#

no its already spawned there

#

yeah i guess so

#

if i am right

#

i am not that too good at

#

this stuf

random cosmos
#

thats alright, did you place it there?

modern harness
#

yeah

#

its gonna stay there always

random cosmos
#

yeah but you want it to not be there when you rejoin

modern harness
#

yeah

#

true

random cosmos
#

so you want to rejoin without restarting the server?

#

or you want the server to save that the part is gone

modern harness
#

yeah

#

i want the server to know that one player touched the part

#

so he can't touch it again

#

only the other players who have not found it

#

let me send you a short clip

random cosmos
#

when chatting with ai might might be better to talk seperately about how you choose to plan certain things before going to another chat about developing, for future reference.

modern harness
#

okay

#

i been working on this for 2 days already

random cosmos
#

when I did a bachelors Degree in software we were forced to do a whole paper (2 month) on just planning how a user is going to interact.

cedar summitBOT
#

studio** You are now Level 2! **studio

wild kiln
#

I can help you with this

#

You need this right?

modern harness
#

yes

#

let me show you

#

look this is the clip

#

Tom??

#

thx sassy and potato

wild kiln
#

Ah

modern harness
#

you see

random cosmos
#

so when the part has been touched the part is destroyed forever?

wild kiln
#

So you want the Points to save and the Part to be removed?

modern harness
#

yes

#

so if the player a touches the part then the games saves it after he rejoins but then he can't see the part but the other players can

wild kiln
#

Okay

#

We can make that work

modern harness
#

I will appericate it

wild kiln
#

Would you mind adding me to the Baseplate your working on?

modern harness
#

sure

#

what is your user

wild kiln
#

1q_87

random cosmos
#

local DataStoreService = game:GetService("DataStoreService")
local pointsDataStore = DataStoreService:GetDataStore("PlayerPoints")
local partTouchDataStore = DataStoreService:GetDataStore("PartTouchData")
local part = game.Workspace:WaitForChild("YourPartName") -- Replace "YourPartName" with the actual part's name

-- Function to handle player data
local function handlePlayerData(player)
    local playerId = player.UserId
    local playerKey = "Points_" .. playerId

    -- Load player's points from datastore
    local success, points = pcall(function()
        return pointsDataStore:GetAsync(playerKey)
    end)

    if success then
        local leaderstats = player:FindFirstChild("leaderstats")
        if not leaderstats then
            leaderstats = Instance.new("Folder")
            leaderstats.Name = "leaderstats"
            leaderstats.Parent = player
        end

        local pointsValue = leaderstats:FindFirstChild("Points")
        if not pointsValue then
            pointsValue = Instance.new("IntValue")
            pointsValue.Name = "Points"
            pointsValue.Value = points or 0
            pointsValue.Parent = leaderstats
        else
            pointsValue.Value = points or 0
        end

        player.AncestryChanged:Connect(function(_, parent)
            if not parent then
                local success, error = pcall(function()
                    pointsDataStore:SetAsync(playerKey, pointsValue.Value)
                end)
                if not success then
                    warn("Failed to save data: " .. error)
                end
            end
        end)
    else
        warn("Failed to load data for player " .. player.Name)
    end
end

-- Check if part has been touched before
local function checkPartTouchedStatus()
    local success, hasBeenTouched = pcall(function()
        return partTouchDataStore:GetAsync("PartTouchedStatus")
    end)

    if success then
        if hasBeenTouched then
            print("The part has been touched before. Destroying the part.")
            part:Destroy()
        else
            print("The part has not been touched before.")
        end
    else
        warn("Failed to check part touched status.")
    end
end

-- Save part touched status
local function savePartTouchedStatus()
    local success, error = pcall(function()
        partTouchDataStore:SetAsync("PartTouchedStatus", true)
    end)
    if not success then
        warn("Failed to save part touched status: " .. error)
    end
end

-- Handle part touched event
part.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        savePartTouchedStatus()
        -- You can handle additional logic here, e.g., award points
        print(player.Name .. " touched the part.")
    end
end)

-- Connect to player added event
game.Players.PlayerAdded:Connect(handlePlayerData)

-- Check part touched status on server start
checkPartTouchedStatus()
#

try that

modern harness
#

does that go in server script service

#

Tom you have to add me

random cosmos
#

or this ```-- File: ServerScriptService/PartTouchTracker.lua

local DataStoreService = game:GetService("DataStoreService")
local pointsDataStore = DataStoreService:GetDataStore("PlayerPoints")
local partTouchDataStore = DataStoreService:GetDataStore("PartTouchData")
local part = game.Workspace:WaitForChild("YourPartName") -- Replace "YourPartName" with the actual part's name

-- Function to handle player data
local function handlePlayerData(player)
local playerId = player.UserId
local playerKey = "Points_" .. playerId

-- Load player's points from datastore
local success, points = pcall(function()
    return pointsDataStore:GetAsync(playerKey)
end)

if success then
    -- Create leaderstats if not exists
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    -- Create Points value
    local pointsValue = Instance.new("IntValue")
    pointsValue.Name = "Points"
    pointsValue.Value = points or 0
    pointsValue.Parent = leaderstats

    -- Save points when player leaves
    player:Connect(function()
        local success, error = pcall(function()
            pointsDataStore:SetAsync(playerKey, pointsValue.Value)
        end)
        if not success then
            warn("Failed to save data: " .. error)
        end)
    end)
else
    warn("Failed to load data for player " .. player.Name)
end

end

-- Check if part has been touched before
local function checkPartTouchedStatus()
local success, hasBeenTouched = pcall(function()
return partTouchDataStore:GetAsync("PartTouchedStatus")
end)

if success and hasBeenTouched then
    print("The part has been touched before. Destroying the part.")
    part:Destroy()
else
    print("The part has not been touched before.")
end

end

-- Save part touched status
local function savePartTouchedStatus()
local success, error = pcall(function()
partTouchDataStore:SetAsync("PartTouchedStatus", true)
end)
if not success then
warn("Failed to save part touched status: " .. error)
end
end

-- Handle part touched event
part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
savePartTouchedStatus()
-- You can handle additional logic here, e.g., award points
print(player.Name .. " touched the part.")
end
end)

-- Connect to player added event
game.Players.PlayerAdded:Connect(handlePlayerData)

-- Check part touched status on server start
checkPartTouchedStatus()```

modern harness
#

and sassy does that go in server script service

#

Thank you SAssy

random cosmos
#

yes

modern harness
#

Thank you sassy soo so much

#

I been

#

so frustrated with that

random cosmos
#

does it work though?

modern harness
#

Thank you so so much

#

yes

random cosmos
#

thats good man im really happy

modern harness
#

can i add you

#

on discord

random cosmos
#

yeah for sure

modern harness
#

i sent you a friend request thank you so much

#

Everyone thanks for you help

#

Do i remove the post now

random cosmos
#

anytime dude

#

you change the tag to solved

modern harness
#

okay thank you

#

sassy

#

how do i change the tag

random cosmos
#

3 little dots at the top, if you hover over it it says more

modern harness
#

Thank you