I’m creating a game that uses npcs to buy boats and have gotten everything I have wanted to work, except a boat detection system.
Basically, I wanted to have it so when a player buys a boat, if there is already a boat there that isnt the players it wont work.
If it also helps, I’ve added a String value equivalent to the player who owns each boat.
If anyone can help me I would be greatful
Proximity Prompt
script.Parent.Triggered:Connect(function(hit)
if hit.Character:FindFirstChild("Humanoid") then
game:GetService("ReplicatedStorage").Chats.SmallBoat:FireClient(hit)
end
end)
LocalScript/ChatHandler
local debounce = false
local cooldown = 5
local Messages = {"So You Want To Buy My Viking Boat","It'll Cost You", "How does 500 Gold Sound?"}
local Reply1 = {"No?", "I Knew I Overpriced Didn't I"}
local Reply2 = {"I Knew You Were Smart", "A Deal Is A Deal", "Good Luck On Your Journey Traveller"}
local Reply3 = {"You Dont Have Enough Gold!", "You're Not Trying To Scam Me Now Are You?"}
game:GetService("ReplicatedStorage").Chats.VikingBoat.OnClientEvent:Connect(function(hit)
if debounce == false then
debounce = true
local GUI = script.Parent.ScreenGui2:Clone()
local Player = hit
local Rig = game.Workspace.Ketil:Clone()
GUI.Parent = script.Parent
GUI.Frame.NpcName.Text = "Ketil"
GUI.Enabled = true
script.Parent.Parent.Character.Humanoid.WalkSpeed = 0
Rig.Parent = GUI.Frame.ViewportFrame
for i, v in pairs(Messages) do
for i = 1, string.len(v) do wait(.025)
script.Parent.NPC_70:Play()
GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
end
wait(1)
end
GUI.Frame.Yes.Visible = true
GUI.Frame.No.Visible = true
GUI.Frame.Yes.MouseButton1Down:Connect(function(plr)
GUI.Frame.Yes.Visible = false
GUI.Frame.No.Visible = false
print(script.Parent.Parent.leaderstats.Gold.Value)
if script.Parent.Parent.leaderstats.Gold.Value < 500 then
for i, v in pairs(Reply3) do
for i = 1, string.len(v) do wait(.025)
script.Parent.NPC_70:Play()
GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
end
wait(1)
end
script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
debounce = false
GUI:Destroy()
else
game:GetService("ReplicatedStorage").Chats.VikingBuy:FireServer(plr)
for i, v in pairs(Reply2) do
for i = 1, string.len(v) do wait(.025)
script.Parent.NPC_70:Play()
GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
end
wait(1)
end
script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
debounce = false
GUI:Destroy()
end
end)
GUI.Frame.No.MouseButton1Down:Connect(function(plr)
GUI.Frame.Yes.Visible = false
GUI.Frame.No.Visible = false
for i, v in pairs(Reply1) do
for i = 1, string.len(v) do wait(.025)
script.Parent.NPC_70:Play()
GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
end
wait(1)
end
script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
debounce = false
GUI:Destroy()
end)
end
end)
Boat Giver
game:GetService("ReplicatedStorage").Chats.VikingBuy.OnServerEvent:Connect(function(plr)
plr.leaderstats.Gold.Value = plr.leaderstats.Gold.Value - 500
for i , v in pairs(game.Workspace:GetDescendants()) do
if v.Name == "Boat1"or v.Name == "Boat2" then
if v.Owner.Value == plr.Name then
v:Destroy()
end
end
end
local boat = game:GetService("ReplicatedStorage").Boats.Boat2:Clone()
boat.Position = Vector3.new(-1078.895, 71.659, -354.827)
boat.Parent = workspace
boat.Owner.Value = plr.Name
end)