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

Checking String Value Via Script Isn't Working?

I am making a brick and when clicked will clone a model in the workspace and place it in the designated parts position. However I need to make some changes in the way it works due to saving data and because of that I need to add a String value inside of the brick and whenever it has a value (in this example Archer Hut) it will clone and place the cloned model in that parts position. Here is the code (I checked the actual string value in workspace and it has the same value as the script needs):


while true do
	wait(0.001)
	if script.Parent.Building.Value == "ArcherHut" then
		print("ArcherHut")
	end
end

2 comments

0

What value is it??

0

It is a string value. Some more information, I am checking the value via a script and I am changing the value via a local script. Please tell me if that changes anything

2 answers

✓ Accepted answer

Is the script a LocalScript? If so, It won't work since LocalScripts don't run in the workspace. You might want to put the LocalScript in StarterPlayer>StarterPlayerScripts.

1 comment

0

That still doesn't work. Oh and its a script however the value is changed by a local script from a GUI.

It's not working because you are changing the value from the client and checking it on the server (it doesn't replicate). You will have to use remote events to change the value of that part:

(This is a simple example, note that this is easily exploitable)

Localscript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("RemoteName") -- Path to the remote

script.Parent.MouseButton1Click:Connect(function() -- Example event
	Remote:FireServer("Archer")
end)

ServerScript( Recommended to be placed in SSS)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("RemoteName")

Remote.OnServerEvent:Connect(function(Player,String)
	Pathtovalue.Value = String
end)

Read more about remote events here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

2 comments

0

Thank you karlo_tr10! That works! However I would like to keep my game away from clients as they are, as you said, very exploitable. Thank you though!

0

Every game has to have that structure. I just said that at this configuration it's exploitable. You just need to take my example and upgrade it so it's not exploitable.

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