Hello, scripter! I’m facing an issue that I’ve been trying to solve, but I keep encountering failures and there are no error messages to guide me. I’m a bit puzzled by this situation. Could you please help me troubleshoot these scripts?
Issue: I have implemented a stats and chance system with buttons that allow players to obtain dirt, wood, moss, woodster, and mudshroom. Everything seems to be working well, except for one problem. When a player obtains dirt (for example, 1 in 1 chance), a message is shown to them individually, not sent to the server. However, for woodster (1 in 10000 chance), which is a rare chance, I want to send a server-wide message. Lastly, for mudshroom (1 in 1 million chance), also very rare, I want to send a global message. Despite my efforts, I’m encountering difficulties in achieving this. Could you provide assistance in resolving this matter?
(I’m not good at script, sorry!)
Here Script:
local RarityService = require(game.ServerStorage.RarityService)
local Rarities = require(game.ServerStorage.Rarities)
local x = require(game.ReplicatedStorage.Data.EternityNum)
local Button = script.Parent
local region3 = Region3.new(Button.Position - (Button.Size/2), Button.Position + (Button.Size/2))
local part = Instance.new("Part")
part.Anchored = true
part.Size = region3.Size
part.CanCollide = false
part.Transparency = 1
part.CFrame = region3.CFrame + Vector3.new(0, 0.75, 0)
part.Parent = Button
local commonItems = {"Dirt", "Wood", "Moss", "Woodster", "Mudshroom"} -- List of common items
local RemoteEvent = game:GetService("ReplicatedStorage"):FindFirstChild("MudshroomMessage")
while wait(.7) do
local PartsInRegion = workspace:FindPartsInRegion3(region3, part, 1000)
for i, v in pairs(PartsInRegion) do
if v.Parent:FindFirstChild("Humanoid") then
local char = v.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local leafCost = 5 -- Cost in leaf
local success, error = pcall(function()
local StatToCost = x.convert(plr:WaitForChild("Stats"):WaitForChild("Leaf").Value)
if x.meeq(StatToCost, leafCost) then
StatToCost = x.sub(StatToCost, leafCost)
plr:WaitForChild("Stats"):WaitForChild("Leaf").Value = x.bnumtostr(StatToCost)
-- Use the rarity system to get the selected item based on chances
local luck = 1
for i = 1, 1 do
local selectedItem = RarityService.chooseIndex(Rarities, luck) -- Using luck factor 1
-- Update the corresponding stat if an item is obtained
if plr:WaitForChild("Stats"):FindFirstChild(selectedItem) then
local statValue = x.convert(plr:WaitForChild("Stats"):WaitForChild(selectedItem).Value)
-- Apply a boost of 1 to the selected special stat
local boostValue = 1
-- Calculate the new stat value with the gain and boost applied
local newStatValue = x.add(statValue, boostValue)
-- Update the stat value
plr:WaitForChild("Stats"):WaitForChild(selectedItem).Value = x.bnumtostr(newStatValue)
else
print("Sorry, you didn't get an item this time.")
-- Handle the case when no item is obtained (common case)
-- In this case, replace with "Dirt"
local dirtStat = plr:WaitForChild("Stats"):WaitForChild("Dirt")
dirtStat.Value = x.bnumtostr(x.add(x.convert(dirtStat.Value), 1)) -- Increment "Dirt" stat by 1
end
end
end
end)
end
end
end
(Actually, this is my first post. I apologize if I have made any mistakes.)