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

Where to put server scripts that will only work on individual players?

Asked by 5 years ago

Since only local scripts can be put on server scripts?

Server script(Stamina Regen):

local plr = script.Parent.Parent
plr.MaxStamina.Value = (plr.Stats.Vitality.Value*4)+100
local MaxStam = plr.MaxStamina.Value
db = false

function regenStamina()
    if not db then
        db = true
        while plr.Stamina.Value<MaxStam do
            plr.Stamina.Value = plr.Stamina.Value + (MaxStam/10)
            if plr.Stamina.Value>MaxStam then
                plr.Stamina.Value = MaxStam
            end
            wait(1)
        end
        if plr.Stamina.Value < 0 then
            plr.Stamina.Value = 0
        end
        db = false
    end
end

function addStamina ()
    MaxStam = (plr.Stats.Vitality.Value*4)+100
    plr.MaxStamina.Value = MaxStam
    regenStamina()
end

function giveStamina()
    addStamina()
    plr.Stamina.Value = MaxStam
end

plr.CharacterAdded:Connect(giveStamina)
plr.Stats.Vitality.Changed:Connect(addStamina)
plr.Stamina.Changed:Connect(regenStamina)

2 answers

Log in to vote
0
Answered by
herrtt 387 Moderation Voter
5 years ago

Use PlayerAdded

game.Players.PlayerAdded:Connect(function(plr) 
    wait()
    plr.MaxStamina.Value = (plr.Stats.Vitality.Value*4) + 100
    local MaxStam = plr.MaxStamina.Value
    local db = false
    —Rest of script
end)

This will work for each individual player, you may have to add a wait(1) or WaitForChild() since the folders and values may not have been added yet.

Ad
Log in to vote
0
Answered by 5 years ago

Script, or ServerScripts, are supposed to handle game mechanics, (for example, in a disasters game, they would handle the disasters). Scripts should always be put into ServerScriptService or the Workspace. On the other hand, LocalScripts are supposed to handle thing with the player, for example health regeneration (or stamina). These scripts are only supposed to go into anything that has Starter in its name (ex. StarterPlayerScripts, StarterGui, StarterPack), with a few exceptions. So your script, which deals with player stamina, should be a LocalScript placed inside of StarterPlayerScripts. also you shoud have something like this:

local plr = game.Players.LocalPlayer
0
It was my original script, however the stamina doesnt regen on real game so I had to put it in server script. xxXTimeXxx 101 — 5y
0
well then in that case you have to use eigher a single script which handles stamina regen for everyone, or use remote events to communicate to the server. i recomend doing something like herrtt mentioned above RiskoZoSlovenska 378 — 5y

Answer this question