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

I can't make the text button give a sword when you have 120 stats. Can someone help?

Asked by 4 years ago
Edited by JesseSong 4 years ago
01local cost = 120
02 
03script.Parent.MouseButton1Click:connect(function(localPlayer)
04 
05if localPlayer.leaderstats.Time.Value >= cost then
06    game.ReplicatedStorage.Sword1:Clone().Parent = localPlayer.Backpack
07    script.Parent.BackgroundColor3 = Color3(0,255,0)
08    wait(2)
09    script.Parent.BackgroundColor3 = Color3(255,255,255)
10    else
11        script.Parent.BackgroundColor3 = Color3(255,0,0)
12        wait(2)
13        script.Parent.BackgroundColor3 = Color3(255,255,255)
14    end
15end)
0
This is a localscript, you need to fire a remote event to give the sword on the server. thecelestialcube 123 — 4y
0
i tried that but it said ettempt to index nil whith leaderstats oligamingthebest 9 — 4y

1 answer

Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
4 years ago
Edited 4 years ago

First off, use RemoteEvents since the FilteringEnabled update came around to stop exploiters.

When using a RemoteEvent it would be like this, put the Sword in ServerStorage, and make a remote in ReplicatedStorage named "BuySword"

Localscript

01local player = game.Players.Localplayer
02 
03script.Parent.MouseButton1Click:connect(function()
04 
05    game.ReplicatedStorage.BuySword:FireServer()
06 
07    if player.leaderstats.Time.Value >= 120 then
08 
09        script.Parent.BackgroundColor3 = Color3(0,255,0)
10            wait(2)
11            script.Parent.BackgroundColor3 = Color3(255,255,255)
12 
13    else
14 
15        script.Parent.BackgroundColor3 = Color3(255,0,0)
View all 21 lines...

Serverscript

01local cost = 120
02 
03game.Players.PlayerAdded:Connect(function(player)
04 
05    local stats = Instance.new("Folder", player)
06    stats.Name = "leaderstats"
07 
08    local Time = Instance.new("NumberValue", stats)
09    Time.Name = "Time"
10 
11end)
12 
13game.ReplicatedStorage.BuySword.OnServerEvent:Connect(function(player)
14 
15    if player.leaderstats.Time.Value >= cost then
View all 21 lines...
0
i did the thing you said to do but it says Players.oligamingthebest.PlayerGui.ScreenGui.TextButton.LocalScript:14: attempt to call a table value oligamingthebest 9 — 4y
Ad

Answer this question