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 3 years ago
Edited by JesseSong 3 years ago
local cost = 120

script.Parent.MouseButton1Click:connect(function(localPlayer)

if localPlayer.leaderstats.Time.Value >= cost then
    game.ReplicatedStorage.Sword1:Clone().Parent = localPlayer.Backpack
    script.Parent.BackgroundColor3 = Color3(0,255,0)
    wait(2)
    script.Parent.BackgroundColor3 = Color3(255,255,255)
    else
        script.Parent.BackgroundColor3 = Color3(255,0,0)
        wait(2)
        script.Parent.BackgroundColor3 = Color3(255,255,255)
    end
end)
0
This is a localscript, you need to fire a remote event to give the sword on the server. thecelestialcube 123 — 3y
0
i tried that but it said ettempt to index nil whith leaderstats oligamingthebest 9 — 3y

1 answer

Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
3 years ago
Edited 3 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

local player = game.Players.Localplayer

script.Parent.MouseButton1Click:connect(function()

    game.ReplicatedStorage.BuySword:FireServer()

    if player.leaderstats.Time.Value >= 120 then

        script.Parent.BackgroundColor3 = Color3(0,255,0)
            wait(2)
            script.Parent.BackgroundColor3 = Color3(255,255,255)

    else

        script.Parent.BackgroundColor3 = Color3(255,0,0)
            wait(2)
            script.Parent.BackgroundColor3 = Color3(255,255,255)

    end

end)

Serverscript


local cost = 120 game.Players.PlayerAdded:Connect(function(player) local stats = Instance.new("Folder", player) stats.Name = "leaderstats" local Time = Instance.new("NumberValue", stats) Time.Name = "Time" end) game.ReplicatedStorage.BuySword.OnServerEvent:Connect(function(player) if player.leaderstats.Time.Value >= cost then game.Serverstorage.Sword1:Clone().Parent = player.Backpack end end)
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 — 3y
Ad

Answer this question