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

My game is giving tools to everyone in the server? lol please help if you are smart

So, to start off with..

It is in a Local Script.

I'm creating a shop script, that you can only buy items with points. When someone purchases the tool with points; everyone gets the tool?

I'm very concerned.

Here's the script:

local Part = game.Workspace.BuyPart
local RS = game:GetService("ReplicatedStorage")
local Sword = RS.Tools:FindFirstChild("SpeedCoil")
local Players = game:GetService("Players")
local Debounce = false

Part.Touched:Connect(function(hit)
	local Player = game.Players.LocalPlayer
	if Player.leaderstats.Points.Value >= 500 then
		if not Debounce then
			Debounce = true
		Sword.Parent = Player.Backpack
		wait(10)
		Debounce = false
	end
	
	local GravityCoil = RS.Tools:FindFirstChild("GravityCoil")
	local Part1 = game.Workspace.BuyPart1
	
	Part1.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
	
			if Player.leaderstats.Points.Value >= 7000 then
				if not Debounce then
					Debounce = true
				GravityCoil.Parent = Player.Backpack
				wait(10)
				Debounce = false
	end
	
	local Part2 = game.Workspace.BuyPart2
	local Tool = RS.Tools:FindFirstChild("PointGiverTool")
	
	Part2.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
	
			if Player.leaderstats.Points.Value >= 10000 then
				if not Debounce then
					Debounce = true
				Tool.Parent = Player.Backpack
				wait(10)
				Debounce = false
			end
			end
			end
			end)
				end
				end
				end)
					end
					end)

1 comment

0

Add a variable named coins set it to the amount you want then do coins.Value = coins.Value - Points.Value on line 10 and line 38 and line 24.

3 answers

✓ Accepted answer
--[[
I optimized your script because there were placements that shouldn't have been made. Such as 3 other Touched events in a touch event.
]]

local Part = game.Workspace.BuyPart
local RS = game:GetService("ReplicatedStorage")
local Sword = RS.Tools:FindFirstChild("SpeedCoil")
local Players = game:GetService("Players")
local Debounce = false
local Player = game.Players.LocalPlayer

Part.Touched:connect(function(hit) -- I close each event after its done its job
	if Player.leaderstats.Points.Value >= 500 and not Debounce then -- Can have multiple conditional statements in one line using 'and'
		Debounce = true
		Sword:Clone().Parent = Player.Backpack -- Clone the part to avoid repetition
		wait(10)
		Debounce = false
	end
end)

local GravityCoil = RS.Tools:FindFirstChild("GravityCoil")
local Part1 = game.Workspace.BuyPart1

Part1.Touched:connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") and Player.leaderstats.Points.Value >= 7000 and not Debounce then
		Debounce = true
		GravityCoil:Clone().Parent = Player.Backpack
		wait(10)
		Debounce = false
	end
end)


local Part2 = game.Workspace.BuyPart2
local Tool = RS.Tools:FindFirstChild("PointGiverTool")

Part2.Touched:connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") and Player.leaderstats.Points.Value >= 10000 and not Debounce then
		Debounce = true
		Tool:Clone().Parent = Player.Backpack
		wait(10)
		Debounce = false
	end	
end)

4 comments

0

Obviously there are more efficient ways of doing this, like gathering them all and having them give the tools based on what value they are holding. I didn't want to alter your script beyond your current style or understanding. Im just giving ideas. Cheers

0

I'm so happy now, you definitely taught me something.

0

Glad to help

0

Also what you did and what that script does it does it only for the local player. Changing the local player and using GetPlayerFromCharacter allows it so anyone can use that. Unless the script is given to everyone then you're fine

That's because you didn't clone it to the backpack. If player has more points then you have to clone it to the backpack otherwise it wont work and will give the tools to everyone and.

Note: If you don't put clone this will just make the thing of the parent which you told the script plus if you want to make a bought script all you have to do is say

coins = 10 -- you can name it to anything you want

coins.Value = coins.Value - Points.Value

Please upvote me if I am correct.

Make sure they're not in Starterpack otherwise they'll be given to the player by default. Put the tools in ServerStorage and then clone them to the player when you need to.

1 comment

0

Thats manually but you can do it with a script.

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