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

How do i use leaderboard stats as variables in scripts?

Asked by
Vicas4 0
5 years ago
Edited 5 years ago

Im editing a finished gun template for my game. I am trying to make the damage of the weapon equal to the leaderboard stat strength.

But i keep getting the error W001 Unknown Global "player" And also, they gun doesnt shoot or work at all when testing in studio. But it works when BaseDamage is set to a number.

This is most of the weapon code (its too long to post):

------------------------------------------Gun info
ToolName="Pistol"
ClipSize=20
ReloadTime=2
Firerate=1
MinSpread=0.002
MaxSpread=0.05
SpreadRate=0.02
BaseDamage=player.leaderstats.strength.Value*player.leaderstats.rebirths.Value--PROBLEM
rays=0
automatic=false
burst=false
shot=false          --Shotgun
BarrlePos=Vector3.new(0,0,0)
Cursors={"rbxasset://textures\\GunCursor.png"}
ReloadCursor="rbxasset://textures\\GunWaitCursor.png"

barrel_1  = script.Parent:findFirstChild("barrelpos1") or script.Parent.Handle
barrel_2 = script.Parent:findFirstChild("barrelpos2") or script.Parent.Handle
double = false  --Double Wielded 
doublemode = 1 -- 1 is alternating, 2 is both

if not game.Lighting:findFirstChild("BulletTexture") then
p = Instance.new("Part")
p.Parent = game.Lighting
p.Name = "BulletTexture"
p.CanCollide = false
p.formFactor = "Custom"
p.Size = Vector3.new(1,0.1,1)
p.Transparency = 1
g = Instance.new("SpecialMesh")
g.Parent = p
end

-------------------------------------
Tool = script.Parent

p = Instance.new("Part")
p.Parent = game.Lighting
p.Name = "BulletTexture"
p.CanCollide = false
p.formFactor = "Custom"
p.Size = Vector3.new(1,0.1,1)
p.Transparency = 1
g = Instance.new("SpecialMesh")
g.Parent = p


GuiEffect = "Sine"

--[[Sine slows down as it nears, 
Bounce overshoots then eases back,
Linear is smooth constant movement, 
and others which amplify the magnitude of the effects 
(EX: Quad slows down later than Sine,
 Elastic overshoots goal a few times.)]]


-------------------------------------
local a = Instance.new("ScreenGui")
local Ammo = Instance.new("TextLabel",a)
Ammo.Name = "Ammo"
Ammo.Position = UDim2.new(.25,0,01,0)
Ammo.Size = UDim2.new(.01,0,-.3,0)
Ammo.BackgroundTransparency = 1
Ammo.FontSize = Enum.FontSize.Size18
-------------------------------------
equiped=false
dw = false
sp=script.Parent
RayLength=1000
Spread=.15
enabled=true
reloading=false
down=false
r=game:service("RunService")
last=0
last2=0
last3=0
last4=0
last5=0
last6=0
UseDouble = false
Bullet=Instance.new("Part")
Bullet.Name="Bullet"
Bullet.BrickColor=BrickColor.new("White")
Bullet.Anchored=true
Bullet.CanCollide=false
Bullet.Locked=true
Bullet.Size=Vector3.new(1,1,1)
Bullet.Transparency=0.5
Bullet.formFactor=0
Bullet.TopSurface=0
Bullet.BottomSurface=0
mesh=Instance.new("SpecialMesh")
mesh.Parent=Bullet
mesh.MeshType="Brick"
mesh.Name="Mesh"
mesh.Scale=Vector3.new(.15,.15,1)


function check()
    sp.Name=ToolName..""
end

function computeDirection(vec)
    return vec.unit
end

-----------------------------------------------------Raycasting functions

function raycursive(start,dir,ignore) -- bad pun lol
    newdir = (start+dir)-start
    local hit,pos = workspace:findPartOnRay(Ray.new(start,newdir.unit*999.999),ignore)
    if hit and rays <= 5 then
        if (hit.CanCollide==false and (hit.Parent.Name~="" and hit.Name ~= "Left Arm" and hit.Name ~= "Left Leg" and hit.Name ~= "Right Arm" and hit.Name ~= "Right Leg")) then
            rays = rays + 1
            return raycursive(pos,dir,hit)
        else
            rays = 0
            return hit,pos
        end
    else
        return hit,pos
    end
end
-------------------------------------


function tagHumanoid(humanoid)
    local plr=game.Players:playerFromCharacter(sp.Parent)
    if plr~=nil then
        local tag=Instance.new("ObjectValue")
        tag.Value=plr
        tag.Name="creator"
        tag.Parent=humanoid
        delay(2,function()
            if tag~=nil then
                tag.Parent=nil
            end
        end)
    end
end


function reload(mouse)
    reloading=true
    mouse.Icon=ReloadCursor
    local bulletshow = game.Players.LocalPlayer.PlayerGui:findFirstChild("BulletShow")
    if bulletshow then
        btload = (ClipSize-sp.Ammo.Value)/ClipSize
        btloadtime = btload*ReloadTime
        bulletshow.Ammo.Text = ""..script.Parent.Ammo.Value.." / "..ClipSize.." "
    end
    while sp.Ammo.Value<ClipSize and reloading and enabled do
        wait(ReloadTime/ClipSize)
        if reloading then
            sp.Ammo.Value=sp.Ammo.Value+1
            check()
        else
            break
        end
    end
    check()
    mouse.Icon=Cursors[1]
    reloading=false
   bulletshow.Ammo.Text = ""..script.Parent.Ammo.Value.." / "..ClipSize.." "
end

This is the code i have in ServerScriptStorage that sets the leaderboard stats:

local datastore = game:GetService("DataStoreService")
local data1 = datastore:GetDataStore("mystrengthdata")
local data2 = datastore:GetDataStore("myrebirthsdata")

game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local rebirths = Instance.new("IntValue", leaderstats)
rebirths.Name = "rebirths"
local strength = Instance.new("IntValue", leaderstats)
strength.Name = "strength"
local rebirthcost = Instance.new("IntValue", leaderstats)
rebirthcost.Name = "rebirthcost"
local points = Instance.new("IntValue", leaderstats)
points.Name = "points"
strength.Value = data1:GetAsync(player.UserId) or 1
data1:SetAsync(player.UserId, strength.Value)
rebirths.Value = data2:GetAsync(player.UserId) or 1
data2:SetAsync(player.UserId, rebirths.Value)


game.Players.PlayerRemoving:connect(function()
data1:SetAsync(player.UserId, strength.Value)
data2:SetAsync(player.UserId, rebirths.Value)

end)
end)

I would be thankful for any help!

0
Post the full code! How do you expect to be helped if you don't post anything? User#19524 175 — 5y
0
I Posted almost everything that i think is relevant Vicas4 0 — 5y

Answer this question