I have a script here, it is quite short and self explanatory. It is currently a Client sided function under a LocalScript. However, the purpose I am using it for, requires it to be Server sided instead. How would I go about making this server sided?
Any help would be greatly appreciated. Thank you!
wait(1) local Player = workspace:FindFirstChild(script.Parent.Name) local P = game.Players.LocalPlayer if not Player:FindFirstChild("Team") then local value = Instance.new("StringValue") value.Name = 'TEAM' value.Parent = Player value.Value = P.Team.Name end
You can't make client-sided script a server-sided script. However, you can use Remote Event or Remote Function to let LocalScript and Script communicate with each other.
I'll show you how to use Remote Event. It sends a signal to another script.
LocalScript:
wait(1) local ReplicatedStorage = game:GetService("ReplicatedStorage") local addValue = ReplicatedStorage:WaitForChild(YOUR REMOTE EVENT'S NAME) local Player = workspace:FindFirstChild(script.Parent.Name) local P = game.Players.LocalPlayer if not Player:FindFirstChild("Team") then addValue:FireServer(P) end
Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local addValue = ReplicatedStorage:WaitForChild(YOUR REMOTE EVENT'S NAME) function addingValue(player) local value = Instance.new("StringValue") value.Name = 'TEAM' value.Parent = Player value.Value = P.Team.Name end addValue.OnServerEvent:connect(addingValue)
I hope I helped you :)
This is the updated version, it's mostly @KrzysiekRoblox's code, but I did have to do some tweaking. I still gave him credit for basically giving me it. LocalScript:
wait(1) local ReplicatedStorage = game:GetService("ReplicatedStorage") local addValue = ReplicatedStorage:WaitForChild("UpdateTeam") local Player = workspace:FindFirstChild(script.Parent.Name) if not Player:FindFirstChild("Team") then addValue:FireServer() end
Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local addValue = ReplicatedStorage:WaitForChild("UpdateTeam") function addingValue(player) local value = Instance.new("StringValue") value.Name = 'TEAM' value.Parent = player.character value.Value = player.Team.Name end addValue.OnServerEvent:Connect(addingValue)
Thanks,