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

how to fix this bool value contradiction?

it prints both "true" and "false" when i click the Warrior unit. how do i fix this?

THIS IS THE OUTPUT OF IT WHEN I CLICK THE UNIT

Selected Value: true Select Script(Normal Script)
Selected Value: false Control Script(Local Script)
> StarterPack	
> > Units
> > > Warrior
> > > > ClickDetector
> > > > Owner
> > > > Select
> > > >  Selected -- (Bool Value)
> > > >  Control -- (Localscript)

it clones the warrior to the workspace when the player clicks a gui button

Select Script

local Warrior = script.Parent
local Selected = Warrior.Selected

function Clicked()
	

Selected.Value = true
print("Selected Value:", Selected.Value ,"Select Script(Normal Script)")

end

script.Parent.ClickDetector.MouseClick:connect(Clicked)

Control Script

local Warrior = script.Parent
local Selected = Warrior.Selected
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
	local hit = mouse.Hit.p






function onClick()
	
	print("Selected Value:", Selected.Value ,"Control Script(Local Script)")


	
	if Warrior.Selected.Value == true
	
	then
	
	 Warrior.Position = mouse.Hit.p
end
end



mouse.Button1Down:connect(onClick)

1 answer

Make assumptions

The network latency means that when you click, your code runs locally sooner than the code on the server does, and even then any changes that thw server makes have to replicate back to the client in order for you to see the changes in the LocalScript.

Solution? Set it to true in the LocalScript too. You're assuming it's true when it's clicked anyway.

2 comments

0

would there be any way to combine the selection script and the control? (since it needs mouse Target, i dont think so, but im just learning scripting.)

0

Just do it on both sides of the network why is this hard to understand?

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