#Code problem

216 messages · Page 1 of 1 (latest)

green arch
#

local plr = game.Players.LocalPlayer
local tools = game.ReplicatedStorage.Tools
local button = script.Parent
local leaderstats = plr:WaitForChild("leadestats")
local cash = leadestats:FindFirstChild("Cash")
local bgcolor = button.BackgroundColor3
local char = plr.Character
local hum = char:WaitForChild("Humanoid")

local price = 10
local toolname = "Weight1"

button.MouseButton1Click:Connect(function()

if cash.Value ≥ price then
    
    hum:UnequipTools()
    plr:WaitForChild("Backpack"):ClearAllChildren()
    
    tools[toolname]:Clone().Parent = plr:WaitForChild("Backpack")
    
    button.BackgroundColor3 = Color3.new(0, 1, 0.4)
    button.Text = "Success!"
    wait(2)
    button.BackgroundColor3 = bgcolor
    button.Text = "Item1"
end

end)

#

This is code

#

@hardy stag ty so so so much

#

@hardy stag how i can delete this post

#

my past code was used by a youtuber, it worked for him but not for me, now it works, thanks

#

Where

split craneBOT
#

studio** You are now Level 3! **studio

green arch
#

Where to solve post

mortal scroll
green arch
#

Ok, can you help me with one thing@hardy stag

#

Ok

#

After

#

player.leaderstats.cash -= 10

mortal scroll
#

You CANT change Values using LOCAL SCRIPT to get cash, sell things or anything like that, it will be visually

green arch
#

Bro

#

I put player.leaderstats.cash -= 10 in this

#

How to fix

vagrant raft
#

You can use localscript

mortal scroll
#

You are trying to change "cash" value using A LOCAL SCRIPT, that's just worthless BRO

vagrant raft
#

Remotevent

green arch
mortal scroll
#

ok BRO

vagrant raft
#

💀

mortal scroll
#

Do you even know the difference between LOCAL SCRIPT and SERVER SCRIPT?

#

BRO

vagrant raft
#

🤯

mortal scroll
#

To fix it you need to change 2 things

  1. From Local Script to Server Script ("Script")
  2. plr variable
    easy
#

@green arch

green arch
#

I didn't understand anything from you. I'll find out myself

mortal scroll
green arch
#

Lmao

mortal scroll
#

lmao... what?

#

Whats so funny?

#

Thats the way you can learn

green arch
#

@mortal scroll

mortal scroll
#

Cool, but no way I can help you only with that

#

BRO

green arch
#

local remote = game.ReplicatedStorage.Remotes.AddStrenght

remote.OnServerEvent:Connect(function(player, togive)

local strenght = player:WaitForChild("leaderstats").Strenght

strenght.Value = strenght.Value + togive.Value

end)

mortal scroll
#

Do a print

print(strenght.Value, togive.Value)

I need to see which one if nil, prob togive.Value

green arch
#

Add that in script?

mortal scroll
#

No, write it down on a paper

green arch
#

What paper

mortal scroll
#

sarcasm

green arch
#

Not working

#

Nevermind

hardy stag
#

@green arch

#

can u send a script where u call this remote eVenT

#

u need to do

#
local remote = game.ReplicatedStorage.Remotes.AddStrenght

remote.OnServerEvent:Connect(function(player, togive)

    local strenght = player:WaitForChild("leaderstats").Strenght

    strenght.Value = strenght.Value + togive
end)
#

and

#

when u call

#
local remote = game.ReplicatedStorage.Remotes.AddStrenght

remote:FireServer(here is number, for example 25)
#

and then 'togive' will equals to 25

mortal scroll
hardy stag
mortal scroll
hardy stag
mortal scroll
hardy stag
#

can I kiss you..

#

👰🏿‍♀️

#

contentProv:PreloadAsync({life})

mortal scroll
hardy stag
mortal scroll
hardy stag
mortal scroll
hardy stag
mortal scroll
green arch
#

@hardy stag that is not problem, i have new problem

hardy stag
mortal scroll
green arch
#

local plr = game.Players.LocalPlayer
local tools = game.ReplicatedStorage.Tools
local button = script.Parent
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:FindFirstChild("Cash")
local bgcolor = button.BackgroundColor3
local char = plr.Character
local hum = char:WaitForChild("Humanoid")

local price = 10
local toolname = "Weight1"

button.MouseButton1Click:Connect(function(plr)

if cash.Value > price then
    plr.leaderstats.cash.Value -= 10
    
    hum:UnequipTools()
    plr:WaitForChild("Backpack"):ClearAllChildren()

    tools[toolname]:Clone().Parent = plr:WaitForChild("Backpack")

    button.BackgroundColor3 = Color3.new(0, 1, 0.4)
    button.Text = "Success!"
    wait(2)
    button.BackgroundColor3 = bgcolor
    button.Text = "Item1"
end

end)

hardy stag
green arch
mortal scroll
green arch
#

@hardy stag can you help me

hardy stag
#

idk

#

i never fixed it

green arch
#

@mortal scroll ?

split craneBOT
#

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

mortal scroll
hardy stag
#

if i have this problem i just leave and watch youtube

hardy stag
#

or father idc

mortal scroll
#

NO SON! You are not allowed to watch p

green arch
#

I also tried with a regular script and the same problem appeared again

mortal scroll
hardy stag
hardy stag
mortal scroll
hardy stag
mortal scroll
mortal scroll
hardy stag
#

rlly

#

i dont saw his explorer

mortal scroll
#

Based on the fact that he is trying to do something with a TextButton/ImageButton, thats clear for me that he is trying to use PlayerGui

hardy stag
#

can u become stronger using father's milk ?

mortal scroll
#

Maybe troll

hardy stag
green arch
mortal scroll
#

But didn't your father when for milk a few year ago? (joke)

green arch
#

...

mortal scroll
green arch
#

Script

hardy stag
#

made in photopea

#

in 5 mins

#

cuz am broken child

mortal scroll
green arch
hardy stag
#

BRO

#

@mortal scroll

#

u need to use local scripts to add leaderstats value

green arch
#

Yes

mortal scroll
green arch
hardy stag
#

try to

mortal scroll
# green arch

Good, do

local plr = script.Parent.Parent.Parent.Parent.Parent.Parent

And print(plr) to check if its ok

hardy stag
#

local leaderstats = script.Parent.Parent.Parent.Parent.Parent.leadestats

#

lol

mortal scroll
green arch
#

Where to put print(plr)

mortal scroll
hardy stag
mortal scroll
hardy stag
#

pro scripter

#

1 one wrote horror game in 1 local script

#

@mortal scroll teach me TeleportService

#

i mean my dad

mortal scroll
hardy stag
mortal scroll
hardy stag
#

now i understand anything about space

mortal scroll
#

Awesome, teach me now

green arch
#

Againn

mortal scroll
#

Your name is "LOGIKRE"?

#

@green arch

green arch
#

Jes

#

Yes

mortal scroll
#

Good, that great

#

We got the player as we should

#

Now lemme see the other error

green arch
#

Code?

mortal scroll
green arch
#

What

mortal scroll
#

Can you test the game and show me whats inside the player instance? (from Players > You Name)

green arch
#

Players is empty

hardy stag
mortal scroll
#

You need to start the game (press play to test)

green arch
gritty island
split craneBOT
#

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

hardy stag
#

im Ukrainian

#

so idc

mortal scroll
#

Change this in your script:

local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
local tools = game.ReplicatedStorage.Tools
local button = script.Parent
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:FindFirstChild("Cash")
local bgcolor = button.BackgroundColor3
local char = plr.Character
local hum = char:WaitForChild("Humanoid")

local price = 10
local toolname = "Weight1"

button.MouseButton1Click:Connect(function(plr)

    if cash.Value > price then
        cash.Value -= 10

        hum:UnequipTools()
        plr:WaitForChild("Backpack"):ClearAllChildren()

        tools[toolname]:Clone().Parent = plr:WaitForChild("Backpack")

        button.BackgroundColor3 = Color3.new(0, 1, 0.4)
        button.Text = "Success!"
        wait(2)
        button.BackgroundColor3 = bgcolor
        button.Text = "Item1"
    end
end)
green arch
#

Russia and ukraine is same

gritty island
hardy stag
green arch
mortal scroll
green arch
#

Im sorry

hardy stag
gritty island
hardy stag
#

hep me

hardy stag
gritty island
mortal scroll
#

Doesn't matter what are you, who are you and all that as long as you are a good person with good morals, empathy and all the good things

green arch
#

the money is deleted from my account but I do not receive my purchased item

mortal scroll
#

Any error?

green arch
#

Yep

mortal scroll
#
print(tools[toolname])
mortal scroll
green arch
mortal scroll
#
plr:WaitForChild("Backpack"):ClearAllChildren()

here is the problem, lemme open Roblox Studio to see something

green arch
#

Ok im waiting...

hardy stag
mortal scroll
#

Create a variable

local backpack = plr:WaitForChild("Backpack")

Somewhere under where you defined plr

mortal scroll
green arch
mortal scroll
#
local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
local tools = game.ReplicatedStorage.Tools
local button = script.Parent
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:FindFirstChild("Cash")
local bgcolor = button.BackgroundColor3
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local backpack = plr:WaitForChild("Backpack")

local price = 10
local toolname = "Weight1"

button.MouseButton1Click:Connect(function()
    if cash.Value > price then
        cash.Value -= 10

        hum:UnequipTools()
        backpack:ClearAllChildren()
        
        local toolClone = tools[toolname]:Clone()
        toolClone.Parent = backpack

        button.BackgroundColor3 = Color3.new(0, 1, 0.4)
        button.Text = "Success!"
        wait(2)
        button.BackgroundColor3 = bgcolor
        button.Text = "Item1"
    end
end)```
#

Try this

green arch
#

Omgggggg

#

Broooo

#

Its workingggg

#

Tyyy

mortal scroll
#

Awesome

hardy stag
#

added 1 value and changed 1 stroke:

green arch
#

Im making data save for backpack and i have problem...

#

local ToolFolder = game:GetService("ServerStorage"):FindFirstChild("SavedTools")
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")

game.Players.PlayerAdded:Connect(function(Player)
local ToolData = SaveData:GetAsync(Player.UserID)

if ToolData ~= nil then
    for i, v in pairs(ToolData) do
        if ToolFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
            ToolFolder[v]:Clone().Parent = Backpack
            ToolFolder[v]:Clone().Parent = StarterGear
        end
    end
end

Player.CharacterRemoving:Connect(function(Character)
    Character:WaitForChild("Humanoid"):UnequipTools()        
end)

end)

game.Players.PlayerRemoving:Connect(function(Player)
local ToolTable = {}

for i, v in pairs(Player.Backpack:GetChildren()) do
    table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil then
    SaveData:SetAsync(Player.UserID, ToolTable)
end

end)

echo arch
green arch
#

local ToolFolder = game:GetService("ServerStorage"):FindFirstChild("SavedTools")
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")

game.Players.PlayerAdded:Connect(function(Player)
local ToolData = SaveData:GetAsync(Player.UserId)

if ToolData ~= nil then
    for i, v in pairs(ToolData) do
        if ToolFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
            ToolFolder[v]:Clone().Parent = Backpack
            ToolFolder[v]:Clone().Parent = StarterGear
        end
    end
end

Player.CharacterRemoving:Connect(function(Character)
    Character:WaitForChild("Humanoid"):UnequipTools()        
end)

end)

game.Players.PlayerRemoving:Connect(function(Player)
local ToolTable = {}

for i, v in pairs(Player.Backpack:GetChildren()) do
    table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil then
    SaveData:SetAsync(Player.UserId, ToolTable)
end

end)