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

Why are my remote scripts not setting my values to false?

Asked by 6 years ago

I have a food part which has two scripts in them. One of them is the touch script which fires a remote event to a local script:

Script:

local repstorage = game:GetService("ReplicatedStorage")
    local remote = repstorage:WaitForChild("Remote2")

    function onTouch(hit)
        local plr = hit.Parent.Name
    remote:FireClient(game.Players:WaitForChild(plr))
    end
    script.Parent.Touched:Connect(onTouch)

Local Script in PlayerGui:

local repstorage = game:GetService("ReplicatedStorage")
    local remote = repstorage:WaitForChild("Remote2")

    remote.OnClientEvent:connect(function(first)
        script.Parent.Parent.Backpack.Ineatbox.Value = true
        if script.Parent.Creature.Creature.Value == "Single-Celled Organism" and script.Parent.Parent.Backpack.Ineatbox.Value == true then
        script.Parent.Parent.Backpack.Eating.Value = true
        end
    end)

The other script is the touch end script which should disable both values which will stop the food level from going up:

local function TouchEndeds(hit)
        local plr = hit.Parent.Name
        if hit.Parent:FindFirstChild("Humanoid") then
        game.Players:WaitForChild(plr).Backpack.Eating.Value = false
        game.Players:WaitForChild(plr).Backpack.Ineatbox.Value = false
        end
        end
    script.Parent.TouchEnded:Connect(TouchEndeds)

For some reason the Variables don't set to false which lets the food value continue to rise. Nothing is being output into the output. I am not too sure what to do to fix this so help would be appreciated.

2 answers

Log in to vote
0
Answered by
iladoga 129
6 years ago

First of all, you have an argument that doesnt exist on the local script for the onclient event. Also all values (unless its a variable) should be set via a server script.Unless you want that value to be changed only with that client.

Ad
Log in to vote
-2
Answered by
oggy521 72
6 years ago

You're firing a remote event to a local script. Remote events are from local to global. If you wish, you can use a remote event, fire it to a global script, which does the same thing to the player, ie, setting your value to false.

0
Wrong. Remote events can be from global to local. User#21908 42 — 6y

Answer this question