Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I fix my script that when you touch a part you gain a point in your stats?

Asked by 3 years ago

Hello! I am asking once again....

I am just a beginner so I don't know why my script won't work...

This is my General Script where I tried creating a save stat system but it didn't work....

local datastore = game:GetService("DataStoreService")
local mydatastore = datastore:GetDataStore("DataStorage")

local playerTable = {}
local rp = game.ReplicatedStorage

-- Save Data
game.Players.PlayerAdded:Connect(function(player)

    playerTable[player] = {Level = 0,Experience = 0,Str = 0,Inventory = 0}
    local currentLevel = mydatastore:GetAsync("savedlevel"..player.UserId)
    local currentExp = mydatastore:GetAsync("savedExp"..player.UserId)
    local currentStr = mydatastore:GetAsync("savedStr"..player.UserId)
    local currentinventory = mydatastore:GetAsync("savedinventory"..player.UserId)

    playerTable[player].Level = currentLevel
    playerTable[player].Experience = currentExp
    playerTable[player].Str = currentStr
    playerTable[player].Inventory = currentinventory

    wait(1)

    player.PlayerGui.Main.Inventory.ScreenGui.StatsFrame.Frame.LevelValueText = playerTable[player].Level
    player.PlayerGui.Exp.Frame.xpValue.Text = playerTable[player].Experience
end)

-- Save Data    

-- Give Data
rp.sCrystalTrig.OnServerEvent:Connect(function(player)

    playerTable[player].Experience = playerTable[player].Experience + 1
    wait(0.6)
    player.PlayerGui.Exp.Frame.xpValue = playerTable[player].Experience.."/".. 10
    wait()

end)
-- Give Data

The script inside it

local sCrystal = script.Parent
local rp = game.ReplicatedStorage

sCrystal.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if hit.Parent:FindFirstChild("HumanoidRootPart") then

            local player = game.Players:GetPlayerFromCharacter(hit.Parent)  

            rp.sCrystalTrig:FireClient(player)
            print("Consumed")

        end
    end
end) 

For me I think the problem is in the General script because the script in the part is working ("shows print text")

So basically I wanted to gain experience when I touch the part.... but the experience is not changing text in my Gui whenever I touch the part; It only sends me the Consumed text in output.

Any help is appreciated and Thanks in advance!

1 answer

Log in to vote
0
Answered by 3 years ago

got a discord, then dm me: Blue Duck#8902 I know how to solve this question, but it's hard for me to explain so I'll send screenshots

0
sended u my f.r MachoMasterKirby 2 — 3y
0
Um can I send u a friend request on dis and u help me with my scripting problem? (My user is idk v.2) TypicalVictorlks 17 — 3y
0
*idk v.2 #1003 TypicalVictorlks 17 — 3y
Ad

Answer this question