How can you connect two scripts with each other without remote functions/events?

Hello,

So i’m trying to make something that when the value of a bool is 1 that an error gets shown.(the error is an txt label within startergui)

But that doesn’t works and I have no clue why it doesn’t works. And in case your wondering im tweening the label. Cause if I only had to make it visible then I wouldn’t have made this topic.

I really would appreciate it if someone is going to help me with this!

Here are the both scripts;

The tween script; (its a localscript)


local object = script.Parent
object.AnchorPoint = Vector2.new(0, 0.25)
object.Position = UDim2.new(1.01, 0, 0.422, 0)

wait(2)

object:TweenPosition(UDim2.new(0.765, 0, 0.422, 0))

wait(5)

object:TweenPosition(UDim2.new(1.01, 0, 0.422, 0))



The one that checks if the value is 1; (this one is server-sided connected with remote function)

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local tvRequest = Instance.new("RemoteFunction")
tvRequest.Parent = ReplicatedStorage
tvRequest.Name = "CreateOldTvRequest"



local function tvRequestFunction(player)

	local Cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
	local leaderstats = player.leaderstats

	print(Cash.Value)

	if Cash.Value >= 0 then

		
		Cash.Value -= 0 --Subtract 0 from the Player's Cash

		local oldtvclone = game.ReplicatedStorage.Tvs.OldTv.PartsOfOldTv:Clone()
		oldtvclone.Parent = game.Workspace
		oldtvclone.Name = "OldTvClone"
		
		
		print(oldtvclone)
		print(oldtvclone.Parent)
		
		
		
		for i, v in pairs(oldtvclone:GetChildren()) do
			v.CanCollide = true
			v.Transparency = 0
			v.Anchored = false
		end


		
		local value = Instance.new("BoolValue")
		value.Name = "PackageChecker"
		value.Parent = game.Workspace:WaitForChild("OldTvClone")
		
		local tv = game.Workspace:WaitForChild("OldTvClone")
		local checker = game.Workspace.Packages
		
		if tv and checker.Value == 0 then
			wait(5)
			
			print("<\\-")

			tv:Destroy()
			
			
			local tvPackage = game.ReplicatedStorage.Packages.PackagesConveyor.OldTvSellingBox:Clone()
			tvPackage.Parent = game.Workspace
			tvPackage.Name = "OldTvPackage"
			checker.Value = 1
			if tv and checker.Value == 1 then
				-- don't know what to put here yet....
			end

		end
		
		
		
	else
		print("You don't have enough cash")
	end
end

tvRequest.OnServerInvoke = tvRequestFunction

Is there a specific reason why you don’t want to use a remote function or event?

Cause its impossible to use them right now. Cause if your using remote functions/events you need to have a function like MouseButton1Click:Connect()

Firing an event doesn’t require those functions? Unless I’m misunderstanding something about what you want.

They do right? Or am I completely miss understanding it?

That’s for events but you get the idea.

All events require that syntax to be able to “listen” for them. I don’t think there’s any way to connect two separate scripts without any kind of event, whether that be a bindable event, property changed event, etc. Events are how scripts communicate.

Remote events and remote function is to connect client to server and server to client. You can use stringValues or intValues. Also you can use moduleScripts and bindable event and bindable functions.

I read those but they all have built-in functions. And I don’t need that cause thats affecting it which I don’t need to do it.

Is that helpfull for me? So the error can appear?

It looks like you have a server script, and you want the client to be able to “respond” to something in the server script. This is impossible without remote events/functions or replicated objects (such as value objects, and even then would require property changed events), since the only things the client sees are replicated objects (in workspace or replicatedStorage), and as such those objects are the only way to “communicate” between client and server scripts.

I’d suggest making a remote event for each player, having the player’s local script listen for its fire, and have the server fire the event with the information you want the client to see, such as “1”.

Isn’t that unnecessary? Cause I put the value there so it can check if the value is one if so then the error needs to pop up. So all I need to know is how I can make the server-script connecting to the localscript in the PlayerGui.

And if I use remote functions it needs built-in functions am I right or am I totally wrong? If i’m right is there an other way to connect them cause I don’t need functions like PlayerAdded or MouseButton1Click.

Server Script:

if number = 1 then
     FireClientEvent
end

Local Script:

OnClientEvent:
     ChangeTextToError

This is pseudocode but you get the idea.

And your sure that will work cause it looks so simple…

Yes, that’s a basic idea of how it would work. See the article linked above for code examples.

Ok i’ll try that tomorrow cause I got to go now.

1 Like

You probably don’t need to use remote functions in this case, events should be enough. You can use value objects like I said before since they would be replicated in workspace or replicatedstorage, but even then you have to connect the client’s script to the value object’s PropertyChangedEvent, and is definitely less performant than just using events (although probably not by much).

So the server script should be like this?;

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local tvRequest = Instance.new("RemoteFunction")
tvRequest.Parent = ReplicatedStorage
tvRequest.Name = "CreateOldTvRequest"



local function tvRequestFunction(player)

	local Cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
	local leaderstats = player.leaderstats

	print(Cash.Value)

	if Cash.Value >= 0 then

		
		Cash.Value -= 0 --Subtract 0 from the Player's Cash

		local oldtvclone = game.ReplicatedStorage.Tvs.OldTv.PartsOfOldTv:Clone()
		oldtvclone.Parent = game.Workspace
		oldtvclone.Name = "OldTvClone"
		
		
		print(oldtvclone)
		print(oldtvclone.Parent)
		
		
		
		for i, v in pairs(oldtvclone:GetChildren()) do
			v.CanCollide = true
			v.Transparency = 0
			v.Anchored = false
		end


		
		local value = Instance.new("BoolValue")
		value.Name = "PackageChecker"
		value.Parent = game.Workspace:WaitForChild("OldTvClone")
		
		local tv = game.Workspace:WaitForChild("OldTvClone")
		local checker = game.Workspace.Packages
		
		if tv and checker.Value == 0 then
			wait(5)
			
			print("<\\-")

			tv:Destroy()
			
			
			local tvPackage = game.ReplicatedStorage.Packages.PackagesConveyor.OldTvSellingBox:Clone()
			tvPackage.Parent = game.Workspace
			tvPackage.Name = "OldTvPackage"
			checker.Value = 1
			if tv and checker.Value == 1 then
				
				local ReplicatedStorage = game:GetService("ReplicatedStorage")
				local Players = game:GetService("Players")

				local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventTest")
				remoteEvent:FireClient(player)
				
			end

		end
		
		
		
	else
		print("You don't have enough cash")
	end
end

tvRequest.OnServerInvoke = tvRequestFunction

But how does the local script needs to be? Cause I already have this putten in it;(this script is in the error gui btw)


local object = script.Parent
object.AnchorPoint = Vector2.new(0, 0.25)
object.Position = UDim2.new(1.01, 0, 0.422, 0)

wait(2)

object:TweenPosition(UDim2.new(0.765, 0, 0.422, 0))

wait(5)

object:TweenPosition(UDim2.new(1.01, 0, 0.422, 0))





You need an OnClientEvent:Connect function and then have it do what you want it to do.

1 Like