Make the gold thing pass the parameter of the remotefunction
use my format I sent earlier
It shows you how to change gui by server
How do I add the players to the list?
also I got this error: RenderStepped event can only be used from local scripts
by scripting it, or just do. ‘All Players’
I mean it is better to just add a remote even when player has changed the GUI, make it so you can pass the GOLD thing onto the parameter and then make the rest of the script on the server. That’s why not anything was being passed throught or printed.
Should I keep it as a local script?
That is correct. If you would like to show the placeholder tower for every player, send a Bindable Event to other players with the: Action*, CFrame, Tower, Color, Rotation
Action is what you will do - for optimization
“Destroy”
“Move”
I don’t want the placeholder to show to every player. Just the player that is placing the tower.
the power of parameters. (oh my god the limit)
(removethirtycharracterruleabc)
Listen to me. Make a RemoteEvent called “TowerEvent” on the ReplicatedStorage. Fire it when player was going to put the tower, pass the parameters “Gold” and everything you want to that and make the rest of the script to the new server script. Starts it with a >
Game.ReplicatedStorage.TowerEvent.OnServerEvent:Connect(function(Gold)
The rest of the Script.
end)
I forgot to tell you that I stole the code from my other tds game.
singABCsfourtimes(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
local Players = game:GetService("Players")
local PhysicsService = game:GetService("PhysicsService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local gold = Players.LocalPlayer:WaitForChild("Gold")
local events = ReplicatedStorage:WaitForChild("Events")
local functions = ReplicatedStorage:WaitForChild("Functions")
local requestTowerFunction = functions:WaitForChild("RequestTower")
local towers = ReplicatedStorage:WaitForChild("Towers")
local spawnTowerEvent = events:WaitForChild("SpawnTower")
local camera = workspace.CurrentCamera
local gui = script.Parent
local towerToSpawn = nil
local canPlace = false
local rotation = 0
local placedTowers = 0
local maxTowers = 20
local function UpdateGold()
gui.Gold.Text = gold.Value
end
UpdateGold()
gold.Changed:Connect(UpdateGold)
local function MouseRaycast(exclude)
local mousePosition = UserInputService:GetMouseLocation()
local mouseRay = camera:ViewportPointToRay(mousePosition.X, mousePosition.Y)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = exclude
local raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000, raycastParams)
return raycastResult
end
local function RemovePlaceholderTower()
if towerToSpawn then
towerToSpawn:Destroy()
towerToSpawn = nil
rotation = 0
end
end
local function AddPlaceholderTower(name)
local towerExists = towers:FindFirstChild(name)
if towerExists then
RemovePlaceholderTower()
towerToSpawn = towerExists:Clone()
towerToSpawn.Parent = workspace
for i, object in ipairs(towerToSpawn:GetDescendants()) do
if object:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(object, "Tower")
object.Material = Enum.Material.ForceField
object.Transparency = 0.3
end
end
end
end
local function ColorPlaceholderTower(color)
for i, object in ipairs(towerToSpawn:GetDescendants()) do
if object:IsA("BasePart") then
object.Color = color
end
end
end
gui.Towers.Title.Text = "Towers: " .. placedTowers .. "/" .. maxTowers
for i, tower in pairs(towers:GetChildren()) do
local button = gui.Towers.Template:Clone()
local config = tower:WaitForChild("Config")
button.Name = tower.Name
button.Image = config.Image.Texture
button.Visible = true
button.LayoutOrder = config.Price.Value
button.Price.Text = config.Price.Value
button.Parent = gui.Towers
button.Activated:Connect(function()
local allowedToSpawn = requestTowerFunction:InvokeServer(tower.Name)
if allowedToSpawn then
AddPlaceholderTower(tower.Name)
end
end)
end
UserInputService.InputBegan:Connect(function(input, processed)
if processed then
return
end
if towerToSpawn then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if canPlace then
spawnTowerEvent:FireServer(towerToSpawn.Name, towerToSpawn.PrimaryPart.CFrame)
placedTowers += 1
gui.Towers.Title.Text = "Towers: " .. placedTowers .. "/" .. maxTowers
RemovePlaceholderTower()
end
elseif input.KeyCode == Enum.KeyCode.R then
rotation += 90
end
end
end)
RunService.RenderStepped:Connect(function()
game:GetService("ReplicatedStorage").TowerEvent:FireServer(Gold, towerToSpawn, ...)
if towerToSpawn then
local result = MouseRaycast({towerToSpawn})
if result and result.Instance then
if result.Instance.Parent.Name == "TowerArea" then
canPlace = true
ColorPlaceholderTower(Color3.new(0,1,0))
else
canPlace = false
ColorPlaceholderTower(Color3.new(1,0,0))
ColorPlaceholderTower(Color3.new(1,0,0))
end
local x = result.Position.X
local y = result.Position.Y + towerToSpawn.Humanoid.HipHeight + (towerToSpawn.PrimaryPart.Size.Y / 2)
local z = result.Position.Z
local cframe = CFrame.new(x,y,z) * CFrame.Angles(0, math.rad(rotation), 0)
towerToSpawn:SetPrimaryPartCFrame(cframe)
end
end
end)
Ok so, Do I put the code after the gold script or do I just put the gold script in there?
You also need to make a sanity check to do not lag the entire server cuz of that.
Ok, let’s optimize this so it’s easier to find a solution
Add a modulescript in ReplicatedStorage
Ok, what do I do next?
roblox moderation sucks