How do I make a local script make a server script get something from server storage?

I’m making a GUI that allows the character to morph into a custom character, but I can’t figure out how to make the local script reference something in server storage to the server

please feel free to ask me to rephrase, if i wrote it confusingly!

here is the local script

rs = game:GetService("ReplicatedStorage")
rme = rs.changeModel
f = script.Parent

--//-

f.plrBuilder.MouseButton1Click:Connect(function()
	local wantedChar = game:GetService("ServerStorage").PlayerEnemies.CharacterBuilder --I realize that you can't access serverstorage from a local script
	rme:FireServer(wantedChar)
end)

f.plrAdmin.MouseButton1Click:Connect(function()
	local wantedChar = game:GetService("ServerStorage").PlayerEnemies.AdminOnly
	rme:FireServer(wantedChar)
end)

and here is the server script

pe = game:GetService("ServerStorage"):WaitForChild("PlayerEnemies")

game.ReplicatedStorage.changeModel.OnServerEvent:Connect(function(player, wantedChar)
	local oldChar = player.Character
	local newChar = wantedChar:Clone()

	newChar.HumanoidRootPart.Anchored = false
	newChar:SetPrimaryPartCFrame(oldChar.PrimaryPart.CFrame)
	player.Character = newChar
	newChar.Parent = workspace
end)

If there are better methods of going about making a morph gui entirely, I’d also like to hear that! Thank you in advance.

You can’t, if you want something that can be seen by both server and client, then you would have to put it in ReplicatedStorage.

You could make it fire the remote with the name of the character that you want.

rs = game:GetService("ReplicatedStorage")
rme = rs.changeModel
f = script.Parent

--//-

f.plrBuilder.MouseButton1Click:Connect(function()
	rme:FireServer("CharacterBuilder")
end)

f.plrAdmin.MouseButton1Click:Connect(function()
	rme:FireServer("AdminOnly")
end)

pe = game:GetService("ServerStorage"):WaitForChild("PlayerEnemies")

game.ReplicatedStorage.changeModel.OnServerEvent:Connect(function(player, CharName)
	local wantedChar = pe:FindFirstChild(CharName)
	if not wantedChar then return end
	
	local oldChar = player.Character
	local newChar = wantedChar:Clone()

	newChar.HumanoidRootPart.Anchored = false
	newChar:SetPrimaryPartCFrame(oldChar.PrimaryPart.CFrame)
	player.Character = newChar
	newChar.Parent = workspace
end)

Thank you, this works perfectly! I’m kind of new to remote events, so thanks for the advice!

1 Like

A solution to this is using remote events.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.