###When you test in studio, everything runs locally. This is why LocalScripts may have access to server-side only services, such as ServerStorage or ServerScriptService. There is no separation between the server and client. It all runs on the client.
###When you play in a local/real server, the separation comes in. But with FilteringEnabled, they're separated even more, and this separation is much more apparent.
###Your current code does what it does, but the changes don't replicate, most likely because your game is FilteringEnabled, and everything is being done by the client. You should handle the cloning to the server. Although technically it would be bad to check the requirements (such as checking if player has enough money) on the client, you don't want to overwhelm the server with all of this checking. Use a RemoteFunction to get the price of the GravityCoil, and a RemoteEvent to handle the cloning.
local rep = game:GetService"ReplicatedStorage"
local plr = game:GetService("Players").LocalPlayer
local price = rep:WaitForChild("GetPrice"):InvokeServer"GravityCoil"
local giveTool = rep:WaitForChild"GiveTool"
script.Parent.MouseButton1Click:Connect(function()
if plr.leaderstats.Money.Value >= price then
giveTool:FireServer"GravityCoil"
end
end)
###Server script coding;
local rep = game:GetService"ReplicatedStorage"
local getPrice = rep:WaitForChild"GetPrice"
local giveTool = rep:WaitForChild"GiveTool"
giveTool.OnServerEvent:Connect(function(player, toolName)
rep[toolName]:Clone().Parent = player.Backpack
rep[toolName]:Clone().Parent = player.StarterGear
end)
local GetToolPrice
GetToolPrice = function(player, toolName)
return rep[toolName].Price.Value
end
getPrice.OnServerInvoke = GetToolPrice
###On a side note, don't use Lighting as storage, as this is in no way supported by ROBLOX. Learn more here.
4 comments
Why is your tool in lighting? Using Lighting as storage is in no way supported by ROBLOX, FYI.
Please use code blocks.
make this a local script and add wait(5) to the start
Why would they wait 5 seconds