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

Change a players stats with a script being enabled/disabled?

Asked by
soutpansa 120
7 years ago

So.. I've asked this question before but I might have a better solution, I just want some input.

I have a tool in my game, that boosts walk speed/hp/attack damage. (attack damage value is called FAP, and it effects skill damage as well as basic attacks, like punches) Every time the player uses this however, they can just reset and keep the stat gain (FAP value) or leave the game and save the value. I was wondering, what if I made a script with the stat gain on it, and when it is enabled(enabled with left click and disabled after a certain time) the stats go up, and when the player dies the script is disabled. Do you think that it will work?

Here is the script as it is now:

bin=script.Parent  
me = script.Parent.Parent.Parent
local thrust = Instance.new("BodyVelocity")
enabled = true


function onButton1Down(mouse) 
    if enabled == false then 
        return
    end

torso = bin.Chest:clone()
larm = bin.LArm:clone()
rarm = bin.RArm:clone()
lleg = bin.LLeg:clone()
rleg = bin.RLeg:clone()
horns = bin.Horns:clone()

    char = bin.Parent.Parent.Character
    enabled = false
    game:GetService("Chat"):Chat(me.Character.Head, "....", Enum.ChatColor.Red)
        me.Character.Humanoid.WalkSpeed = 0
    wait(1)


if larm ~= nil then
local larmweld = Instance.new("Weld")
    larmweld.Parent = larm
    larmweld.Part0 = larmweld.Parent
    larmweld.Part1 = char:findFirstChild("Left Arm")
    larmweld.C1 = CFrame.new(0, 0, 0)
    larm.Parent = char
end

wait(1)
if rarm ~= nil then
local rarmweld = Instance.new("Weld")
    rarmweld.Parent = rarm
    rarmweld.Part0 = rarmweld.Parent
    rarmweld.Part1 = char:findFirstChild("Right Arm")
    rarmweld.C1 = CFrame.new(0, 0, 0)
    rarm.Parent = char
end
game:GetService("Chat"):Chat(me.Character.Head, "...", Enum.ChatColor.Red)
    wait(1)


if rleg ~= nil then
local  rlegweld = Instance.new("Weld")
     rlegweld.Parent =  rleg
     rlegweld.Part0 = rlegweld.Parent
     rlegweld.Part1 = char:findFirstChild("Right Leg")
     rlegweld.C1 = CFrame.new(0, 0, 0)
     rleg.Parent = char
end

wait(1)


if lleg ~= nil then
local llegweld = Instance.new("Weld")
    llegweld.Parent = lleg
    llegweld.Part0 = llegweld.Parent
    llegweld.Part1 = char:findFirstChild("Left Leg")
    llegweld.C1 = CFrame.new(0, 0, 0)
    lleg.Parent = char
end
wait(.5)
if horns ~= nil then
local hornsweld = Instance.new("Weld")
    hornsweld.Parent = horns
    hornsweld.Part0 = hornsweld.Parent
    hornsweld.Part1 = char.Head
    hornsweld.C1 = CFrame.new(0, 0, 0)
    horns.Parent = char
end
aa = Instance.new("Sound")
        aa.SoundId = "http://www.roblox.com/asset/?id=342472438"
        aa.Parent = torso
aa.Volume = 2
        aa:play()
wait(1)

if torso ~= nil then
local torsoweld = Instance.new("Weld")
    torsoweld.Parent = torso
    torsoweld.Part0 = torsoweld.Parent
    torsoweld.Part1 = char.Torso
    torsoweld.C1 = CFrame.new(0, 0, 0)
    torso.Parent = char
end
aa = Instance.new("Sound")
        aa.SoundId = "http://www.roblox.com/asset/?id=262498455"
        aa.Parent = torso
aa.Volume = 2
aa.Looped = true
        aa:play()
wait(1)
game:GetService("Chat"):Chat(me.Character.Head, "...", Enum.ChatColor.Red)
wait(0.5)

me.Character.Humanoid.WalkSpeed = me.Character.Humanoid.WalkSpeed + 60
me.Character.Humanoid.MaxHealth = me.Character.Humanoid.MaxHealth + 500
me.Character.Humanoid.Health = me.Character.Humanoid.Health + 500
me.Levelss.FAP.Value = me.Levelss.FAP.Value + 200


wait(120)

    if char:findFirstChild("Chest") ~= nil then
        char.Chest:remove()
    end
    if char:findFirstChild("LArm") ~= nil then
        char.LArm:remove()
    end
    if char:findFirstChild("RArm") ~= nil then
        char.RArm:remove()
    end
    if char:findFirstChild("LLeg") ~= nil then
        char.LLeg:remove()
    end
    if char:findFirstChild("RLeg") ~= nil then
        char.RLeg:remove()
    end
    if char:findFirstChild("Horns") ~= nil then
        char.Horns:remove()
    end


game:GetService("Chat"):Chat(me.Character.Head, "Gotta rest...", Enum.ChatColor.Green)
me.Character.Humanoid.WalkSpeed = me.Character.Humanoid.WalkSpeed - 44
me.Character.Humanoid.MaxHealth = me.Character.Humanoid.MaxHealth - 500
me.Character.Humanoid.Health = me.Character.Humanoid.Health - 500
me.Levelss.FAP.Value = me.Levelss.FAP.Value - 200
    wait(35)
    enabled = true
end
function onDe()

char = bin.Parent.Parent.Character
    --if char:findFirstChild("ForceField") ~= nil then
        --char.ForceField:remove()
    --end

local stuff = player.Character:getChildren()
end

function onSelected(mouse)

print("Selected") 

mouse.Icon = "rbxasset://textures\\GunCursor.png" 
mouse.Button1Down:connect(function() onButton1Down(mouse) end) 
end



bin.Selected:connect(onSelected) 
bin.Deselected:connect(onDe) 

0
stat gain part starts on line 102 soutpansa 120 — 7y
0
attack damage is called fap? lol Async_io 908 — 7y
0
yea. It was when I was working early in the game, I reset the testers stats cause I changed how damage worked, and I needed a new damage value so I just called it FAP. xD soutpansa 120 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

If you are trying to save the value then the easiest way I can think of would be to put the values in _G

http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#G

for example when the player dies set values to:

_G.Speed = me.Character.Humanoid.WalkSpeed
_G.MaxHealth = me.Character.Humanoid.MaxHealth
_G.Health = me.Character.Humanoid.Health
_G.FAP = me.Levelss.FAP.Value
_G.Data = true

And when they spawn again

if _G.Data then
     me.Character.Humanoid.WalkSpeed = _G.Speed
     me.Character.Humanoid.MaxHealth = _G.MaxHealth
     me.Character.Humanoid.Health = _G.Health
     me.Levelss.FAP.Value = _G.FAP
end

If this is not what you were asking then please clarify

Ad

Answer this question