Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

0

This is a localscript, you need to fire a remote event to give the sword on the server.

0

i tried that but it said ettempt to index nil whith leaderstats

1 answer

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)

1 comment

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

This discussion is preserved as it was. New answers, comments, and votes are closed.