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

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

Asked by 4 years ago

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)
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. JesseSong 3916 — 4y

3 answers

Log in to vote
1
Answered by
Infocus 144
4 years ago
--[[
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)
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 Infocus 144 — 4y
0
I'm so happy now, you definitely taught me something. maxpax2009 340 — 4y
0
Glad to help Infocus 144 — 4y
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 Infocus 144 — 4y
Ad
Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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.

Log in to vote
0
Answered by 4 years ago

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.

0
Thats manually but you can do it with a script. JesseSong 3916 — 4y

Answer this question