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

Script works in studio but not in the real game? It's probably simple, but beyond me.

Asked by 6 years ago

So I am messing with a hunger/thirst system thing. For example if you click with the water bottle it's supposed to become empty. There's this script which it connects with, that gives the player the values of the things like "Hunger" "Thirst" "Total Hunger" and so on. For some reason the water bottle script doesnt seem to be connecting with the other script. Here is the bottle script.

bottle = script.Parent;


function DrinkWater(player)
    player.Thirst.Value = player.Thirst.Value + s.thirstQuenching;
    if player.Thirst.Value > player.TotalThirst.Value then
        player.Thirst.Value = player.TotalThirst.Value;
    end;
    bottle.Name = "Bottle"; -- Empty the bottle.
end;

bottle.Equipped:connect(function(m)
    local char = bottle.Parent;
    local player = game.Players:GetPlayerFromCharacter(char);
    m.Button1Down:connect(function()
        local target = m.Target;
        if bottle.Name == "Bottle of Water" then
            DrinkWater(player);
        else
            if target then
                if target.Name:lower() == "well water" then
                    bottle.Name = "Bottle of Water";
                end;
            end;
        end;
    end);
end);

Here is the other script

-- Put this script in Workspace or ServerScriptService. Workspace isn't recommended, but it also works.

s = require(workspace.Settings);

-- Putting all of these settings into values inside a character allows each character to individually improve them to their benefit.
-- Basically, it allows for upgrades.
game.Players.PlayerAdded:connect(function(p)
    local th = Instance.new("IntValue", p);
    th.Name = "TotalHunger";
    th.Value = s.totalHunger;
    local hb = Instance.new("IntValue", p);
    hb.Name = "HungerBurnup";
    hb.Value = s.hungerBurnup;
    local hunger = Instance.new("IntValue", p);
    hunger.Name = "Hunger";
    hunger.Value = s.totalHunger;
    local tt = Instance.new("IntValue", p);
    tt.Name = "TotalThirst";
    tt.Value = s.totalThirst;
    local dr = Instance.new("IntValue", p);
    dr.Name = "DehydrationRate";
    dr.Value = s.dehydrationRate;
    local thirst = Instance.new("IntValue", p);
    thirst.Name = "Thirst";
    thirst.Value = s.totalThirst;
    local killRateLow = Instance.new("IntValue", p);
    killRateLow.Name = "KillRateLow";
    killRateLow.Value = s.killRate.low;
    local killRateHigh = Instance.new("IntValue", p);
    killRateHigh.Name = "KillRateHigh";
    killRateHigh.Value = s.killRate.high;
    p.PlayerGui:WaitForChild("Main");
    p.PlayerGui.Main.Updater.Disabled = false;
end);

I tried copying and pasting the values script into a localscript in StartPlayerScripts. It didn't work. I'm sure the reason is simple, but I can't seem to figure it out. Any help is appreciated.

1 answer

Log in to vote
0
Answered by
1xj7 1
6 years ago

the reason why it works in studio is because when you test it, it acts as if you are both the server and the client. when you play the real game, it separates the two. basically, you can't change values from the client, so add a remote event that fires the server and changes the values from there instead of changing them from a local script.

1
You can change values from the client, unless the game has FE, in which case, the values changed by the client will not be replicated to the server. theCJarmy7 1293 — 6y
Ad

Answer this question