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

PlayerGui making global changes in Workspace?

Asked by 4 years ago

Good Evening,

I have built myself a nifty little PlayerGui that operates on localscripts and intvalues stored within the Gui File path. I have 12 intvalues in Workspace that can range from 0-255 - My Gui outputs values to those intvalues(stored in workspace) which I refer to as the 'output'. The Gui is scripted effectively - infact works perfectly, even changing the int values (or so I thought....but only on client side!) - the global server scripts cannot detect this change, or even print the values that I can see clearly set in my client. I am trying to find a way for the server to notice this change. These 'output' values are important (in their 0-255 form) further down the line.

I understand this is probably due to FilteringEnabled, and I understand the theory of local scripts and why they can't alter objects in workspace (darn exploiters) I've had a brief look at RemoteEvents however I can't seem to find a way to implement it, as all of the processing I need is done on Client side. Perhaps if there was a way to take the value from one of the 12 output intvalues in workspace and dump that data (using a RemoteEvent) into a global value - that could potentially work?

Thank you in advance

E

Below is a snippet of code that shows the calculations for 1 of the 12 outputs within a local script in the Gui. This calculates the output and posts it to the intvalues in workspace (variables declared below to help you understand what's going on!)

F01A = script.Parent.F01A

AM = script.Parent.AM
GM = script.Parent.GM

SCPoutput = game.Workspace.SCP
o001 = SCPoutput.o001

    while wait() do
        --*Workspace Output 01*--
        o001.Value = F01A.Value/255*AM.Value/255*GM.Value
    end

2 answers

Log in to vote
0
Answered by
sheepposu 561 Moderation Voter
4 years ago
Edited 4 years ago

The difference between a LocalScript and server script is that one edits things on the client side and the other change things server-wide. What if I need to use a LocalScript to make server-wide changes? The answer is remote events. Below is an example of how to implement a remote event. I have a Button with a LocalScript, a Server Script in ServerScriptService, and a remote event in ReplicatedStorafge called "Click"

LocalScript

local click = false

script.Parent.MouseButton1Click:Connect(function() --Button is clicked
    if not click then
        click = true --They can no longer activate it
        game.ReplicatedStorage.Click:FireServer(math.random(1, 10)) --Passed in a random value form 1-10
    end
end)

game.ReplicatedStorage.Click.OnClientEvent:Connect(function(value) 
    game.ReplicatedStorage.Click:FireServer(value)
end)

Server Script

game.ReplicatedStorage.Click.OnServerEvent(function(plr, value) --The remote was fired with server intention
    wait(0.1)
    workspace.ClickValue.Value = workspace.ClickValue.Value + value --Increase value in workspace
    game.ReplicatedStorage.Click:FireClient(plr, value)
end)

This would create a cycle back and forth and with the wait, the value of ClickValue in workspace would go up by value approximately every tenth of a second.

Hope this helped

Ad
Log in to vote
0
Answered by 4 years ago

Well if i understood you correctly, you are having problems with a Client Side thing operating with a Server thing , that's done with RemoteEvents / RemoteFunctions, but for this we will be using RemoteEvents as they can take data from a Client Sided thing and turn it into a Server Sided thing. My idea is : Putting a RemoteEvent in ReplicatedStorage.Our next step is to fire the remote,firing a remote is very easily, just get the script that you wanted to change the IntValues and add a

game.ReplicatedStorage:FindFirstChild("RemoteEvent"):FireServer()
--You can change the name of the Remote if you want

Now that we have this out of the way we need to find how to send the values. Im sure your values that you want to change are a variable like for example

local Variable = 5
game.ReplicatedStorage:FindFirstChild("RemoteEvent"):FireServer(Variable)

That will send the Variable (Our case is the number 5) to a Server Script.

After you have done this , add a Server Script in any kind of "Script Handling place" (I prefer Workspace, but ServerScriptStorage works aswell) and once you have added it type in and change some stuff with what you made earlier (The Varaible,Remote Name , etc)

game.ReplicatedStorage:FindFirstChild("RemoteEvent").OnServerEvent;Connect(function(player,variable)


end)

--Now make your path to the IntValue in the Workspace,or wherever the IntValue is,and change it with the "variable".

Hope this helped you, if there are any errors don't be afraid to tell me.

Answer this question