Hello guys, Im spideyalvaro999
I have a problem with these tools because the powers of the scripts aren’t working, for example, the speed coils doesn’t run or a body weapon, such as a sword, doesnt even generate. This only happend when you buy it from the shop I created, because when I put it on the starter pack works perfectly. Here I leave you the scripts: -Leaderstats script(It includes leaderstats, DataStore and some irrelevant lines about remotes events)(Normal Script)
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local shopItems = game:GetService(“ServerStorage”):WaitForChild(“ShopItems”) – Where tools are held
local DataStore = game:GetService(“DataStoreService”)
local ds = DataStore:GetDataStore(“CashSaveSystem”)
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local points = Instance.new("IntValue",leaderstats)
points.Name = "Points"
points.Value = ds:GetAsync(player.UserId)or 0
ds:SetAsync(player.UserId, points.Value)
points.Changed:connect(function()
ds:SetAsync(player.UserId, points.Value)
end)
while true do
wait(20)
points.Value = points.value + 1
end
end)
game.Players.PlayerRemoving:Connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.point.Value)
end)
replicatedStorage.GetInfo.OnServerInvoke = function(player,item)
return shopItems[item].Points.Value
end
RemoteEvent.OnServerEvent:Connect(function(player, Value)
player.leaderstats.Points.Value = player.leaderstats.Points.Value - Value
end)
replicatedStorage.CheckSale.OnServerInvoke = function(player,item)
local price = shopItems[item].Points.Value
if player.leaderstats.Points.Value >= price then
player.leaderstats.Points.Value = player.leaderstats.Points.Value - price
local gear = shopItems[item][item]:Clone()
gear.Parent = player.StarterGear
local gear = shopItems[item][item]:Clone()
gear.Parent = player.Backpack
return true
else
return false
end
end
-Script of the Shop(I only have script on the buy button so I leave one)(LocalScript)
local player = game:GetService(“Players”).LocalPlayer
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
script.Parent.MouseButton1Click:Connect(function(click)
if player.leaderstats.Points.Value >= 900 then
RemoteEvent:FireServer(900)
game.ReplicatedStorage.Library.DualMegaCoil:Clone().Parent = player:WaitForChild("Backpack")
end
end)
Ok, so the remote event I told you about earlier, you want to include the game.ReplicatedStorage.Library.DualMegaCoil:Clone().Parent = player:WaitForChild("Backpack") inside of the OnServerEvent as well.
You just need to move the game.ReplicatedStorage.Library.DualMegaCoil:Clone().Parent = player:WaitForChild("Backpack") into the server script with the onserverevent function. Any replication of tools needs to be handled by the server. If you desire, you could do
You’re not going to belive this. I wrote some things wrong and now it seems to work but it clone the tools 3 times when i buy it once. Do I have to do osmething with the fire server?
That’s strange. Open up the output and see if anything errors. You can also add a print statement in your server script to see if it prints that three times as well
But the thing comes stranger. When I buy an object, it buys me 4 objects more without oaying it. For example I buy 1 coil and they give me4 for the price of 1
Give me a second but I had an idea of putin this:
RemoteEvent.OnServerEvent:Connect(function(player, Value, Item) –
player.leaderstats.Points.Value = player.leaderstats.Points.Value - Value
game.ReplicatedStorage.Library[Item]:Clone().Parent = player:WaitForChild(“Backpack”)
end)
For every object
Ohh, you need to do it for every object, but it’s not the server script you need to edit… That will only work for the DualMegaCoil. The server script is designed to accept whatever input you pass from the local script. So for each button click, you will need to set each individual parameter, but you can fire the same event. So like for another object, the 1st parameter could be 500, and the second one would be like “SpeedCoil”.
Ohhh yeah… just stick with what I did with the game.ReplicatedStorage.Library[Item]:Clone().Parent = player:WaitForChild("Backpack"), and you will only get the item you buy, if you set up each button individually, in a local script. You really won’t need to touch the server script much.
Oh, you can only have one onserverevent per remote event. You should stick with just one of those functions, and use game.ReplicatedStorage.Library[Item]:Clone().Parent = player:WaitForChild("Backpack") But instead, create multiple MouseButton1Down functions for each button, with each one passing their own Value and Item to the server, in the FireServer parameters