and so hello everyone, I created a script on the local side and after the player buys a boost, it passes through the remote event and is accepted on the server and then the boost already has the player but it does not work, I do not know what the problem is, help me solve any help is appreciated server script
local script
local timer = script.Parent.Timer
local freeButton = script.Parent.FreeButton
local randomButton1 = script.Parent.RandomButton1
local boost = game.ReplicatedStorage.BoostRemote
local randomButton2 = script.Parent.RandomButton2
local Daily = require(game.ReplicatedStorage.ModulesScript.DailyModule)
local function selectRandomReward()
local reward = Daily.Items[math.random(1, #Daily.Items)]
return reward
end
local function handlePurchase(button)
local coins = player:FindFirstChild("Coins")
if coins then
local reward = selectRandomReward()
if reward.Price <= coins.Value then
coins.Value = coins.Value - reward.Price
if reward.Name == "boost" then
button.Image = "rbxassetid://6552275507"
elseif reward.Name == "Coins" then
button.Image = "rbxassetid://13249588501"
boost:FireServer(reward.Duration)
end
end
end
end
freeButton.MouseButton1Click:Connect(function()
handlePurchase(freeButton)
end)
randomButton1.MouseButton1Click:Connect(function()
handlePurchase(randomButton1)
end)
randomButton2.MouseButton1Click:Connect(function()
handlePurchase(randomButton2)
end)
You have boostremote twice on the server script:
boostremote.OnServerEvent:Connect(function(player, reward)
boostremote.OnServerEvent:Connect(function(reward) -- remove
if reward == 1 then
activateBoost(player, "15M")
elseif reward == 2 then
activateBoost(player, "1H")
elseif reward == 3 then
activateBoost(player, "6H")
elseif reward == 4 then
activateBoost(player, "12H")
end
end) -- remove
end)
it didn’t help in the solution, I still don’t get a boost after the purchase.
the player is nil inside handlePurchase():
local timer = script.Parent.Timer
local freeButton = script.Parent.FreeButton
local randomButton1 = script.Parent.RandomButton1
local boost = game.ReplicatedStorage.BoostRemote
local randomButton2 = script.Parent.RandomButton2
local Daily = require(game.ReplicatedStorage.ModulesScript.DailyModule)
local function selectRandomReward()
local reward = Daily.Items[math.random(1, #Daily.Items)]
return reward
end
local function handlePurchase(button)
local coins = player:FindFirstChild("Coins")
if coins then
local reward = selectRandomReward()
if reward.Price <= coins.Value then
coins.Value = coins.Value - reward.Price
if reward.Name == "boost" then
button.Image = "rbxassetid://6552275507"
elseif reward.Name == "Coins" then
button.Image = "rbxassetid://13249588501"
boost:FireServer(reward.Duration)
end
end
end
end
freeButton.MouseButton1Click:Connect(function()
handlePurchase(freeButton)
end)
randomButton1.MouseButton1Click:Connect(function()
handlePurchase(randomButton1)
end)
randomButton2.MouseButton1Click:Connect(function()
handlePurchase(randomButton2)
end)
this did not help again in solving the problem, I do not know how to solve it.
Please add more of print()
and warn()
and maybe protected call or pcall()
I was able to solve the problem thank you for your help and good luck in the future
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.