Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

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.

1 comment

0

Wrong. Remote events can be from global to local.

This discussion is preserved as it was. New answers, comments, and votes are closed.