My brother and I are bored, so both of us decided to create a TDS type of game. We’re creating a GUI, but our current script doesn’t work.
Code:
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("PlaceTower")
local runService = game:GetService("RunService")
runService.RenderStepped:Connect(function() --test purposes
print("Hello")
end)
local plrService = game:GetService("Players")
local plr = plrService.LocalPlayer
local place = function(tower, pos) --The place function
tower.Position = pos + Vector3.new(0, tower.Position.Y/2, 0)
end
script.Parent.MouseButton1Up:Connect(function()
local mouse = plr:GetMouse()
local turret = script.Parent.Parent:WaitForChild("ViewportFrame"):WaitForChild("Viewport")
local toPlace = turret:Clone()
toPlace.Parent = game.Workspace
toPlace.Name = "Turret"
local connection = runService.RenderStepped:Connect(place(toPlace, mouse.Hit.p)) --Errors here, place is a function and what's nil?
end)
What’s wrong here?
EDIT: Showed line with error to find the problem easily
-- Inside MouseButton1Up
-- before connection
local function Place()
toPlace.Position = pos + Vector3.new(0, toPlace.Position.Y/2, 0)
end
RenderStepped:Connect(Place)
renderstepped’s only function return is step which is the time since the last renderstepped fire actually just use the thing I posted it will work fine
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("PlaceTower")
local runService = game:GetService("RunService")
local plrService = game:GetService("Players")
local plr = plrService.LocalPlayer
function place(tower, pos) --The place function
tower.Position = pos + Vector3.new(0, tower.Position.Y/2, 0)
end
script.Parent.MouseButton1Up:Connect(function()
local mouse = plr:GetMouse()
local mousePos = mouse.Hit.p
local turret = script.Parent.Parent:WaitForChild("ViewportFrame"):WaitForChild("Viewport")
local connection = runService.RenderStepped:Connect(function(step)
local toPlace = turret:Clone()
toPlace.Parent = game.Workspace
toPlace.Name = "Turret"
toPlace.Position = mousePos + Vector3.new(0, toPlace.Position.Y/2, 0)
end)
end)
this is what I use: ```
-- CLIENT
uis.InputBegan:Connect(function(k,gpe)
if not gpe and k.UserInputType == Enum.UserInputType.MouseButton1 then
local ml = mouse.UnitRay
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Whitelist
params.FilterDescendantsInstances = {
workspace.Towers
}
local ray = workspace:Raycast(ml.Origin,ml.Direction*1000,params)
print("raycasting")
if ray and ray.Instance then
print("xd")
--local otherThing = script.Frame:Clone()
--otherThing.Parent = script.Parent.Parent
--local nVector = vector/2
--otherThing.Position = UDim2.new(scale.X*0.5,0,scale.Y,0)
local root = ray.Instance.Parent:FindFirstChild("HumanoidRootPart") or ray.Instance.Parent.Parent:FindFirstChild("HumanoidRootPart") or ray.Instance.Parent.Parent.Parent:FindFirstChild("HumanoidRootPart")
local gui = script.Parent.Parent.Parent.Parent.BillboardGui
gui.Adornee = root
gui.Frame.Visible = not gui.Frame.Visible
end
if selected ~= "" then
TowerPlaceRemote:FireServer(selected,ml)
selected = ""
end
end
end)
-- SERVER
TowerPlaceRemote.OnServerEvent:Connect(function(player,tower,pos)
local TowerModel = Towers:FindFirstChild(tower)
local TowerConfigurationObject = GEC:FindFirstChild(tower)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = getPlayerCharacters()
local ray = workspace:Raycast(pos.Origin,pos.Direction*1000,params)
print(ray.Position,ray.Instance)
local Placement = require(TowerConfigurationObject.Placement)
local Config = TowerConfigurationObject.Config
if ray.Position and ray.Instance then
if ray.Instance.Name ~= Placement["Required_Placement"] then return end
if TowerModel then
print("Tower found.")
local c = TowerModel:Clone()
local Script
local Animations = {}
if TowerConfigurationObject.UseDefaultTowerScript.Value == true then
Script = TowerConfigurationObject.Parent.DefaultTowerScript:Clone()
print(Script:GetFullName())
for i,v in pairs(TowerConfigurationObject.Animations:GetChildren()) do
v:Clone().Parent = Script
end
else
Script = TowerConfigurationObject.UseDefaultTowerScript:FindFirstChildOfClass("Script"):Clone()
print(Script:GetFullName())
for i,v in pairs(TowerConfigurationObject.Animations:GetChildren()) do
v:Clone().Parent = Script
end
end
Config:Clone().Parent = Script
Script.Parent = c
Script.Disabled = false
local num = https:GenerateGUID(false)
local tag = Instance.new("StringValue")
tag.Parent = c
tag.Name = "Identifier"
tag.Value = c.Name .. tostring(num)
local tag = Instance.new("ObjectValue")
tag.Parent = c
tag.Name = "Owner"
tag.Value = player
DataService.AddToPlayerData(player,"Placed_Towers",c.Name .. tostring(num),c)
if Placement then
c.HumanoidRootPart.Position = Vector3.new(ray.Position.X,Positions[Placement["Required_Placement"]]-(Placement.Custom_Y or 0),ray.Position.Z)
else
c.HumanoidRootPart.Position = Vector3.new(ray.Position.X,Positions["Required_Placement"],ray.Position.Z)
end
c.HumanoidRootPart.Anchored = true
c.Parent = workspace.Towers
end
end
end)