I have a module script named MainModule and I am changing the value of a variable called CurrentShaggy and it is saying that the value of that variable is changed in the script that I change it in but when I use that variable in another script, it still says it was an old value.
Local Script:
s = require(workspace:WaitForChild("Modules"):WaitForChild("ShaggyModule"))
m = require(workspace:WaitForChild("Modules"):WaitForChild("MainModule"))
player = game:GetService("Players").LocalPlayer
char = workspace:FindFirstChild(player.Name)
script.Parent.MouseButton1Click:Connect(function()
if s[m.Shop_Selected].owned then
warn("Equip button has not been set up yet")
else
local leaderstats = player:FindFirstChild("leaderstats")
local cash = leaderstats:FindFirstChild("Cash")
if cash.Value >= s[m.Shop_Selected].cost then
cash.Value = cash.Value - s[m.Shop_Selected].cost
s[m.Shop_Selected].owned = true
char:FindFirstChild(m.CurrentShaggy).Name = m.Shop_Selected
m.CurrentShaggy = m.Shop_Selected
print(m.CurrentShaggy) -- Prints correct thing but not changing in other scripts
char:FindFirstChild(m.CurrentShaggy).Handle.Mesh.TextureId = "rbxassetid://"..s[m.CurrentShaggy].textureId
print("Item succefully bought")
script.Parent.Parent.Parent.Parent.Parent.Parent.Visible = false
end
end
end)
Server Script:
size = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("SizeUp")
m = require(workspace:WaitForChild("Modules"):WaitForChild("MainModule"))
s = require(workspace:WaitForChild("Modules"):WaitForChild("ShaggyModule"))
Math = require(workspace:WaitForChild("Modules"):WaitForChild("MathModule"))
debounce = true
DELAY = .1
size.OnServerEvent:Connect(function(player)
if debounce then
debounce = false
local char = workspace:FindFirstChild(player.Name)
local hat = char:FindFirstChild(m.CurrentShaggy)
local mesh = hat.Handle.Mesh
local scaleAmount = s[m.CurrentShaggy].sizepc
local chance = s[m.CurrentShaggy].gemChance
if Math.RandomPercent(chance) then
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 1
m.Gems = m.Gems + 1
print("You got a gem!")
end
mesh.Scale = mesh.Scale + Vector3.new(scaleAmount,scaleAmount,scaleAmount)
player.leaderstats.HatSize.Value = Math.Round(mesh.Scale.X,2)
m.HatSize = player.leaderstats.HatSize.Value
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + s[m.CurrentShaggy].moneypc
m.Cash = m.Cash + s[m.CurrentShaggy].moneypc
wait(DELAY)
debounce = true
end
end)

1 comment
Don't get the character from the workspace.