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 game? even though they dont have enough points

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")

Part.Touched:Connect(function(hit)
    local Player = game.Players.LocalPlayer
    if Player.leaderstats.Points.Value >= 500 then
        Sword.Parent = Player.Backpack
    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
                GravityCoil.Parent = Player.Backpack
    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

                Tool.Parent = Player.Backpack
            end
            end
            end)
                end
                end)
                    end)

I think it has got something to do with the LocalPlayer part.

Best regards.

Maxpax2009.

0
Maybe clone the tool? I don't know i'm not that experienced kingblaze_1000 359 — 4y
0
I appreciate the reply. But it does not work :) maxpax2009 340 — 4y
0
Did you put the tools in ServerStorage or StarterPack? Nistrict 44 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Well this may not solve it but in this segment

Part.Touched:Connect(function(hit)
    local Player = game.Players.LocalPlayer
    if Player.leaderstats.Points.Value >= 500 then
        Sword.Parent = Player.Backpack
    end

you have a function set up for "hit", but you are never using it. I would suggest instead of doing local Player = game.Players.LocalPlayer that you do

local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

this way, it is getting the player from the character, the character is the model of the player, so doing hit.Parent would get you to that character, and you wanna grab the specific player that touched that, so my way of doing this would be

Part.Touched:Connect(function(hit) -- when it gets touched, create a thing for what touched
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent) -- already explained this
    if Player.leaderstats.Points.Value >= 500 and Player then -- adding onto what you did, if there is a player then
        Sword.Parent = Player.Backpack -- clone the sword variable
    end

extra notes - I would put the Sword variable inside the .Touched event, this way it will not delete the previous clone

hope this helps!

0
nice : -) maxpax2009 340 — 4y
Ad

Answer this question